diff --git a/README.md b/README.md index b5cf731..1c6fd38 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # goto -`goto` is a bash utility allowing users to change faster to aliased directories supporting auto-completion :feet: +`goto` is a shell utility allowing users to change faster to aliased directories supporting auto-completion :feet: ## How does it work? @@ -17,7 +17,7 @@ goto dev ## goto completion -`goto` comes with a nice auto-completion script so that whenever you press the `tab` key after the `goto` command, bash prompts with suggestions of the available aliases: +`goto` comes with a nice auto-completion script so that whenever you press the `tab` key after the `goto` command, bash or zsh prompts with suggestions of the available aliases: ```bash $ goto @@ -28,12 +28,21 @@ rubies /home/iridakos/.rvm/rubies ## Installation -Copy the file `goto.bash` somewhere in your filesystem and add a line in your `.bashrc` to source it. +### Via script +Clone the repository and run the install script as super user or root: +```bash +git clone https://github.com/iridakos/goto.git +cd goto +sudo ./install +``` -For example, if you placed the file in your home folder, all you have to do is add the following line to your `.bashrc` file: +### Manually +Copy the file `goto.sh` somewhere in your filesystem and add a line in your `.zshrc` or `.bashrc` to source it. + +For example, if you placed the file in your home folder, all you have to do is add the following line to your `.zshrc` or `.bashrc` file: ```bash -source ~/goto.bash +source ~/goto.sh ``` ## Usage @@ -98,7 +107,7 @@ goto --register blog /mnt/external/projects/html/blog goto -r last_release . ``` and it will automatically be aliased to the whole path. -* Pressing the `tab` key after the alias name, you have the default directory suggestions by bash. +* Pressing the `tab` key after the alias name, you have the default directory suggestions by the shell. ### Unregister an alias @@ -134,6 +143,26 @@ or goto --list ``` +### Expand an alias + +To expand an alias to its value, use: +```bash +goto -x +``` +or +```bash +goto --expand +``` + +#### Example +```bash +goto -x last_release +``` +or +```bash +goto --expand last_release +``` + ### Cleanup To cleanup the aliases from directories that are no longer accessible in your filesystem, use: @@ -171,7 +200,6 @@ goto --version ## TODO * ~~Test on macOS~~ extensively -* Fix `zsh` issues [[#7](https://github.com/iridakos/goto/issues/7), ...] * Write [tests](https://github.com/iridakos/goto/issues/2) ## Contributing diff --git a/goto.bash b/goto.sh similarity index 63% rename from goto.bash rename to goto.sh index aeceb2a..2ca533b 100644 --- a/goto.bash +++ b/goto.sh @@ -1,4 +1,5 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh +# shellcheck disable=SC2039 # MIT License # # Copyright (c) 2018 Lazarus Lazaridis @@ -23,9 +24,10 @@ # Changes to the given alias directory # or executes a command based on the arguments. -function goto() +goto() { local target + _goto_resolve_db if [ -z "$1" ]; then # display usage and exit when no args @@ -54,6 +56,9 @@ function goto() -l|--list) _goto_list_aliases ;; + -x|--expand) # Expand an alias + _goto_expand_alias "$@" + ;; -h|--help) _goto_usage ;; @@ -64,9 +69,15 @@ function goto() _goto_directory "$subcommand" ;; esac + return $? } -function _goto_usage() +_goto_resolve_db() +{ + GOTO_DB="$HOME/.goto" +} + +_goto_usage() { cat <<\USAGE usage: goto [