mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-11-12 08:50:08 +00:00
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
This commit is contained in:
parent
0613232202
commit
79cf2a0d43
2 changed files with 15 additions and 13 deletions
|
@ -4,6 +4,7 @@ This plugin adds a way to reference certain files or folders used frequently usi
|
||||||
a global alias or shortcut.
|
a global alias or shortcut.
|
||||||
|
|
||||||
To use it, add `fastfile` to the plugins array in your zshrc file:
|
To use it, add `fastfile` to the plugins array in your zshrc file:
|
||||||
|
|
||||||
```zsh
|
```zsh
|
||||||
plugins=(... fastfile)
|
plugins=(... fastfile)
|
||||||
```
|
```
|
||||||
|
@ -13,36 +14,38 @@ plugins=(... fastfile)
|
||||||
Example: you access folder `/code/project/backend/database` very frequently.
|
Example: you access folder `/code/project/backend/database` very frequently.
|
||||||
|
|
||||||
First, generate a shortcut with the name `pjdb`:
|
First, generate a shortcut with the name `pjdb`:
|
||||||
|
|
||||||
```zsh
|
```zsh
|
||||||
$ fastfile pjdb /code/project/backend/database
|
$ fastfile pjdb /code/project/backend/database
|
||||||
```
|
```
|
||||||
|
|
||||||
Next time you want to access it, use `§pjdb`. For example:
|
Next time you want to access it, use `§pjdb`. For example:
|
||||||
|
|
||||||
```zsh
|
```zsh
|
||||||
$ cd §pjdb
|
$ cd §pjdb
|
||||||
$ subl §pjdb
|
$ subl §pjdb
|
||||||
```
|
```
|
||||||
|
|
||||||
where § is the fastfile prefix (see [below](#options) for how to change).
|
where § is the fastfile prefix (see [below](#options) for how to change).
|
||||||
|
|
||||||
**Note:** shortcuts with spaces in the name are assigned a global alias
|
**Note:** shortcuts with spaces in the name are assigned a global alias
|
||||||
where the spaces have been substituted with underscores (`_`). For example:
|
where the spaces have been substituted with underscores (`_`). For example:
|
||||||
a shortcut named `"hello world"` corresponds with `§hello_world`.
|
a shortcut named `"hello world"` corresponds with `§hello_world`.
|
||||||
|
|
||||||
|
|
||||||
## Functions
|
## Functions
|
||||||
|
|
||||||
- `fastfile <shortcut_name> <path/to/file/or/folder>`: generate a shortcut.
|
- `fastfile <shortcut_name> [path/to/file/or/folder]`: generate a shortcut.
|
||||||
|
If the second argument is not provided, the current directory is used.
|
||||||
|
|
||||||
- `fastfile_print <shortcut_name>`: prints a shortcut, with the format
|
- `fastfile_print <shortcut_name>`: prints a shortcut, with the format
|
||||||
`<prefix><shortcut_name> -> <shortcut_path>`.
|
`<prefix><shortcut_name> -> <shortcut_path>`.
|
||||||
|
|
||||||
- `fastfile_ls`: lists all shortcuts.
|
- `fastfile_ls`: lists all shortcuts.
|
||||||
|
|
||||||
- `fastfile_rm <shortcut_name> `: remove a shortcut.
|
- `fastfile_rm <shortcut_name>`: remove a shortcut.
|
||||||
|
|
||||||
- `fastfile_sync`: generates the global aliases for the shortcuts.
|
- `fastfile_sync`: generates the global aliases for the shortcuts.
|
||||||
|
|
||||||
|
|
||||||
### Internal functions
|
### Internal functions
|
||||||
|
|
||||||
- `fastfile_resolv <shortcut_name>`: resolves the location of the shortcut
|
- `fastfile_resolv <shortcut_name>`: resolves the location of the shortcut
|
||||||
|
@ -51,7 +54,6 @@ a shortcut named `"hello world"` corresponds with `§hello_world`.
|
||||||
|
|
||||||
- `fastfile_get <shortcut_name>`: get the real path of the shortcut.
|
- `fastfile_get <shortcut_name>`: get the real path of the shortcut.
|
||||||
|
|
||||||
|
|
||||||
## Aliases
|
## Aliases
|
||||||
|
|
||||||
| Alias | Function |
|
| Alias | Function |
|
||||||
|
@ -62,7 +64,6 @@ a shortcut named `"hello world"` corresponds with `§hello_world`.
|
||||||
| ffls | `fastfile_ls` |
|
| ffls | `fastfile_ls` |
|
||||||
| ffsync | `fastfile_sync` |
|
| ffsync | `fastfile_sync` |
|
||||||
|
|
||||||
|
|
||||||
## Options
|
## Options
|
||||||
|
|
||||||
These are options you can set to change certain parts of the plugin. To change
|
These are options you can set to change certain parts of the plugin. To change
|
||||||
|
|
|
@ -44,7 +44,7 @@ function fastfile() {
|
||||||
# The path to the shortcut file
|
# The path to the shortcut file
|
||||||
#
|
#
|
||||||
function fastfile_resolv() {
|
function fastfile_resolv() {
|
||||||
echo "${fastfile_dir}${1}"
|
echo "${fastfile_dir}/${1}"
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -78,9 +78,9 @@ function fastfile_print() {
|
||||||
# (=> fastfile_print) for each shortcut
|
# (=> fastfile_print) for each shortcut
|
||||||
#
|
#
|
||||||
function fastfile_ls() {
|
function fastfile_ls() {
|
||||||
for f in "${fastfile_dir}"/*(NF); do
|
for f in "${fastfile_dir}"/*(N); do
|
||||||
file=`basename "$f"` # To enable simpler handling of spaces in file names
|
file=$(basename "$f") # To enable simpler handling of spaces in file names
|
||||||
varkey=`echo "$file" | tr " " "_"`
|
varkey=$(echo "$file" | tr " " "_")
|
||||||
|
|
||||||
# Special format for columns
|
# Special format for columns
|
||||||
echo "${fastfile_var_prefix}${varkey}|->|$(fastfile_get "$file")"
|
echo "${fastfile_var_prefix}${varkey}|->|$(fastfile_get "$file")"
|
||||||
|
@ -98,15 +98,16 @@ function fastfile_ls() {
|
||||||
function fastfile_rm() {
|
function fastfile_rm() {
|
||||||
fastfile_print "$1"
|
fastfile_print "$1"
|
||||||
rm "$(fastfile_resolv "$1")"
|
rm "$(fastfile_resolv "$1")"
|
||||||
|
unalias "${fastfile_var_prefix}${1}"
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
# Generate the aliases for the shortcuts
|
# Generate the aliases for the shortcuts
|
||||||
#
|
#
|
||||||
function fastfile_sync() {
|
function fastfile_sync() {
|
||||||
for f in "${fastfile_dir}"/*(NF); do
|
for f in "${fastfile_dir}"/*(N); do
|
||||||
file=`basename "$f"` # To enable simpler handling of spaces in file names
|
file=$(basename "$f") # To enable simpler handling of spaces in file names
|
||||||
varkey=`echo "$file" | tr " " "_"`
|
varkey=$(echo "$file" | tr " " "_")
|
||||||
|
|
||||||
alias -g "${fastfile_var_prefix}${varkey}"="'$(fastfile_get "$file")'"
|
alias -g "${fastfile_var_prefix}${varkey}"="'$(fastfile_get "$file")'"
|
||||||
done
|
done
|
||||||
|
|
Loading…
Reference in a new issue