mirror of
https://github.com/iridakos/goto.git
synced 2025-05-16 23:40:16 -07:00
Merge pull request #16 from shawalli/feature/expand_command
Adds a command to expand an alias to its value
This commit is contained in:
commit
17e6131f00
20
README.md
20
README.md
@ -120,6 +120,26 @@ or
|
|||||||
goto --list
|
goto --list
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Expand an alias
|
||||||
|
|
||||||
|
To expand an alias to its value, use:
|
||||||
|
```bash
|
||||||
|
goto -x <alias>
|
||||||
|
```
|
||||||
|
or
|
||||||
|
```bash
|
||||||
|
goto --expand <alias>
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Example
|
||||||
|
```bash
|
||||||
|
goto -x last_release
|
||||||
|
```
|
||||||
|
or
|
||||||
|
```bash
|
||||||
|
goto --expand last_release
|
||||||
|
```
|
||||||
|
|
||||||
### Cleanup
|
### Cleanup
|
||||||
|
|
||||||
To cleanup the aliases from directories that are no longer accessible in your filesystem, use:
|
To cleanup the aliases from directories that are no longer accessible in your filesystem, use:
|
||||||
|
31
goto.sh
31
goto.sh
@ -50,6 +50,9 @@ goto()
|
|||||||
-l|--list)
|
-l|--list)
|
||||||
_goto_list_aliases
|
_goto_list_aliases
|
||||||
;;
|
;;
|
||||||
|
-x|--expand) # Expand an alias
|
||||||
|
_goto_expand_alias "$@"
|
||||||
|
;;
|
||||||
-h|--help)
|
-h|--help)
|
||||||
_goto_usage
|
_goto_usage
|
||||||
;;
|
;;
|
||||||
@ -83,6 +86,8 @@ OPTIONS:
|
|||||||
goto -u|--unregister <alias>
|
goto -u|--unregister <alias>
|
||||||
-l, --list: lists aliases
|
-l, --list: lists aliases
|
||||||
goto -l|--list
|
goto -l|--list
|
||||||
|
-x, --expand: expands an alias
|
||||||
|
goto -x|--expand <alias>
|
||||||
-c, --cleanup: cleans up non existent directory aliases
|
-c, --cleanup: cleans up non existent directory aliases
|
||||||
goto -c|--cleanup
|
goto -c|--cleanup
|
||||||
-h, --help: prints this help
|
-h, --help: prints this help
|
||||||
@ -116,6 +121,25 @@ _goto_list_aliases()
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Expands a registered alias.
|
||||||
|
_goto_expand_alias()
|
||||||
|
{
|
||||||
|
if [ "$#" -ne "1" ]; then
|
||||||
|
_goto_error "usage: goto -x|--expand <alias>"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
local resolved
|
||||||
|
|
||||||
|
resolved=$(_goto_find_alias_directory "$1")
|
||||||
|
if [ -z "$resolved" ]; then
|
||||||
|
_goto_error "alias '$1' does not exist"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "$resolved"
|
||||||
|
}
|
||||||
|
|
||||||
# Lists duplicate directory aliases
|
# Lists duplicate directory aliases
|
||||||
_goto_find_duplicate()
|
_goto_find_duplicate()
|
||||||
{
|
{
|
||||||
@ -268,7 +292,7 @@ _complete_goto_commands()
|
|||||||
local IFS=$' \t\n'
|
local IFS=$' \t\n'
|
||||||
|
|
||||||
# shellcheck disable=SC2207
|
# shellcheck disable=SC2207
|
||||||
COMPREPLY=($(compgen -W "-r --register -u --unregister -l --list -c --cleanup -v --version" -- "$1"))
|
COMPREPLY=($(compgen -W "-r --register -u --unregister -l --list -x --expand -c --cleanup -v --version" -- "$1"))
|
||||||
}
|
}
|
||||||
|
|
||||||
# Completes the goto function with the available aliases
|
# Completes the goto function with the available aliases
|
||||||
@ -321,7 +345,10 @@ _complete_goto_bash()
|
|||||||
prev="${COMP_WORDS[1]}"
|
prev="${COMP_WORDS[1]}"
|
||||||
|
|
||||||
if [[ $prev = "-u" ]] || [[ $prev = "--unregister" ]]; then
|
if [[ $prev = "-u" ]] || [[ $prev = "--unregister" ]]; then
|
||||||
# prompt with aliases only if user tries to unregister one
|
# prompt with aliases if user tries to unregister one
|
||||||
|
_complete_goto_aliases "$cur"
|
||||||
|
elif [[ $prev = "-x" ]] || [[ $prev = "--expand" ]]; then
|
||||||
|
# prompt with aliases if user tries to expand one
|
||||||
_complete_goto_aliases "$cur"
|
_complete_goto_aliases "$cur"
|
||||||
fi
|
fi
|
||||||
elif [ "$COMP_CWORD" -eq "3" ]; then
|
elif [ "$COMP_CWORD" -eq "3" ]; then
|
||||||
|
Loading…
x
Reference in New Issue
Block a user