79cf2a0d43ddda338487c85c420f67fe9c56687f

Author
Shundeev Egor <shundeevegor@gmail.com>
Committer
Marc Cornellà <hello@mcornella.com>
Date

Message

fix(fastfile): fix multiple bugs in plugin (#9574)

- `fastfile_sync` didn't correctly create the aliases
- `fastfile_rm` didn't correctly remove the alias

Fixes #9151
Closes #9574

Diff

  1diff --git a/plugins/fastfile/README.md b/plugins/fastfile/README.md
  2index 37f5b2f5359f9a3f6b177a3655309e6fe35e8bab..32f619ffd05a0bff32ad9411097d92a7ad2d2b50 100644
  3--- a/plugins/fastfile/README.md
  4+++ b/plugins/fastfile/README.md
  5@@ -4,6 +4,7 @@ This plugin adds a way to reference certain files or folders used frequently usi
  6 a global alias or shortcut.
  7 
  8 To use it, add `fastfile` to the plugins array in your zshrc file:
  9+
 10 ```zsh
 11 plugins=(... fastfile)
 12 ```
 13@@ -13,36 +14,38 @@ plugins=(... fastfile)
 14 Example: you access folder `/code/project/backend/database` very frequently.
 15 
 16 First, generate a shortcut with the name `pjdb`:
 17+
 18 ```zsh
 19 $ fastfile pjdb /code/project/backend/database
 20 ```
 21 
 22 Next time you want to access it, use `§pjdb`. For example:
 23+
 24 ```zsh
 25 $ cd §pjdb
 26 $ subl §pjdb
 27 ```
 28+
 29 where § is the fastfile prefix (see [below](#options) for how to change).
 30 
 31 **Note:** shortcuts with spaces in the name are assigned a global alias
 32 where the spaces have been substituted with underscores (`_`). For example:
 33 a shortcut named `"hello world"` corresponds with `§hello_world`.
 34 
 35-
 36 ## Functions
 37 
 38-- `fastfile <shortcut_name> <path/to/file/or/folder>`: generate a shortcut.
 39+- `fastfile <shortcut_name> [path/to/file/or/folder]`: generate a shortcut.
 40+  If the second argument is not provided, the current directory is used.
 41 
 42 - `fastfile_print <shortcut_name>`: prints a shortcut, with the format
 43   `<prefix><shortcut_name> -> <shortcut_path>`.
 44 
 45 - `fastfile_ls`: lists all shortcuts.
 46 
 47-- `fastfile_rm <shortcut_name> `: remove a shortcut.
 48+- `fastfile_rm <shortcut_name>`: remove a shortcut.
 49 
 50 - `fastfile_sync`: generates the global aliases for the shortcuts.
 51 
 52-
 53 ### Internal functions
 54 
 55 - `fastfile_resolv <shortcut_name>`: resolves the location of the shortcut
 56@@ -51,7 +54,6 @@ a shortcut named `"hello world"` corresponds with `§hello_world`.
 57 
 58 - `fastfile_get <shortcut_name>`: get the real path of the shortcut.
 59 
 60-
 61 ## Aliases
 62 
 63 | Alias  | Function         |
 64@@ -62,7 +64,6 @@ a shortcut named `"hello world"` corresponds with `§hello_world`.
 65 | ffls   | `fastfile_ls`    |
 66 | ffsync | `fastfile_sync`  |
 67 
 68-
 69 ## Options
 70 
 71 These are options you can set to change certain parts of the plugin. To change
 72diff --git a/plugins/fastfile/fastfile.plugin.zsh b/plugins/fastfile/fastfile.plugin.zsh
 73index 6288bb2755272caaa997e2f8b70999f37e3748b0..896fed5f78ebeca9367a413da4503b05015988fd 100644
 74--- a/plugins/fastfile/fastfile.plugin.zsh
 75+++ b/plugins/fastfile/fastfile.plugin.zsh
 76@@ -44,7 +44,7 @@ function fastfile() {
 77 #   The path to the shortcut file
 78 #
 79 function fastfile_resolv() {
 80-    echo "${fastfile_dir}${1}"
 81+    echo "${fastfile_dir}/${1}"
 82 }
 83 
 84 #
 85@@ -78,9 +78,9 @@ function fastfile_print() {
 86 #    (=> fastfile_print) for each shortcut
 87 #
 88 function fastfile_ls() {
 89-    for f in "${fastfile_dir}"/*(NF); do
 90-        file=`basename "$f"` # To enable simpler handling of spaces in file names
 91-        varkey=`echo "$file" | tr " " "_"`
 92+    for f in "${fastfile_dir}"/*(N); do
 93+        file=$(basename "$f") # To enable simpler handling of spaces in file names
 94+        varkey=$(echo "$file" | tr " " "_")
 95 
 96         # Special format for columns
 97         echo "${fastfile_var_prefix}${varkey}|->|$(fastfile_get "$file")"
 98@@ -98,15 +98,16 @@ function fastfile_ls() {
 99 function fastfile_rm() {
100     fastfile_print "$1"
101     rm "$(fastfile_resolv "$1")"
102+    unalias "${fastfile_var_prefix}${1}"
103 }
104 
105 #
106 # Generate the aliases for the shortcuts
107 #
108 function fastfile_sync() {
109-    for f in "${fastfile_dir}"/*(NF); do
110-        file=`basename "$f"` # To enable simpler handling of spaces in file names
111-        varkey=`echo "$file" | tr " " "_"`
112+    for f in "${fastfile_dir}"/*(N); do
113+        file=$(basename "$f") # To enable simpler handling of spaces in file names
114+        varkey=$(echo "$file" | tr " " "_")
115 
116         alias -g "${fastfile_var_prefix}${varkey}"="'$(fastfile_get "$file")'"
117     done