├── doc ├── goto.gif ├── goto-logo.png └── goto-logo-40.png ├── LICENSE ├── CHANGELOG.md ├── install ├── README.md └── goto.sh /doc/goto.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iridakos/goto/HEAD/doc/goto.gif -------------------------------------------------------------------------------- /doc/goto-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iridakos/goto/HEAD/doc/goto-logo.png -------------------------------------------------------------------------------- /doc/goto-logo-40.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iridakos/goto/HEAD/doc/goto-logo-40.png -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Lazarus Lazaridis 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to `goto` will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) 6 | and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). 7 | 8 | ## [2.1.0] - 2020-11-15 9 | 10 | ### Added 11 | 12 | - [Allow users to navigate to special directories with goto](https://github.com/iridakos/goto/pull/62) 13 | 14 | ### Change 15 | 16 | - [Improve the display of alias list](https://github.com/iridakos/goto/pull/63) 17 | 18 | ### Fixed 19 | 20 | - [Missing config directory in MacOS](https://github.com/iridakos/goto/pull/64) 21 | 22 | ## [2.0.0] - 2020-01-27 23 | 24 | ### Changed 25 | - Default to $XDG_CONFIG_HOME for storing the goto DB 26 | 27 | ## [1.2.4.1] - 2019-06-02 28 | 29 | ### Fixed 30 | - fix completion for zsh 31 | 32 | ## [1.2.4] - 2019-05-30 33 | 34 | ### Added 35 | - support bash completion for aliases of `goto` 36 | 37 | ## [1.2.3] - 2018-03-14 38 | 39 | ### Added 40 | - align columns when displaying the list of aliases or similar results 41 | 42 | ### Changed 43 | - removed shebang since the script is sourced 44 | - updated README with valid information on supported shells 45 | 46 | ## [1.2.2] - 2018-03-13 47 | 48 | ### Added 49 | - zsh completion for -x, -p, -o 50 | 51 | ## [1.2.1] - 2018-03-13 52 | 53 | ### Added 54 | 55 | - Users can set the `GOTO_DB` environment variable to override the default database file which is `$HOME/.goto` 56 | - Introduced the `CHANGELOG.md` 57 | -------------------------------------------------------------------------------- /install: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # MIT License 3 | # 4 | # Copyright (c) 2018 Lazarus Lazaridis 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | 24 | function _goto_install_error() 25 | { 26 | echo "$@" >&2 27 | } 28 | 29 | #windows check 30 | ON_WINDOWS=false 31 | if [[ "$OSTYPE" == "msys" ]]; then 32 | ON_WINDOWS=true 33 | fi 34 | 35 | # sudo-check 36 | if [ $EUID -ne 0 ] && [ "$ON_WINDOWS" == false ]; then 37 | _goto_install_error 'Please run this script in sudo mode or as root user' 38 | exit 39 | fi 40 | 41 | HOME=$(eval echo "~${SUDO_USER}") 42 | if [[ $ON_WINDOWS = true ]]; then 43 | GOTO_FILE_LOCATION='/usr/bin/goto.sh' 44 | else 45 | GOTO_FILE_LOCATION='/usr/local/share/goto.sh' 46 | fi 47 | 48 | RC="" 49 | if [ -f ~/.bashrc ]; then 50 | RC="$HOME/.bashrc" 51 | elif [ -f ~/.zshrc ]; then 52 | RC="$HOME/.zshrc" 53 | fi 54 | 55 | cp ./goto.sh "$GOTO_FILE_LOCATION" 56 | 57 | if [ -n "$RC" ]; then 58 | # Append source to RC startup file if not already there 59 | if [ "$(grep -c "source $GOTO_FILE_LOCATION" "$RC")" == "0" ]; then 60 | # Append source to RC file 61 | echo -e "\\n\\n# Source goto\\n[[ -s \"$GOTO_FILE_LOCATION\" ]] && source $GOTO_FILE_LOCATION\\n" >> "$RC" 62 | fi 63 | 64 | # shellcheck source=/dev/null 65 | source "$GOTO_FILE_LOCATION" 66 | else 67 | _goto_install_error "Error sourcing goto in your startup file.." 68 | _goto_install_error "E.g ~/.bashrc ~/.zshrc etc.." 69 | fi 70 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # goto 2 | 3 | A shell utility allowing users to navigate to aliased directories supporting auto-completion :feet: 4 | 5 | ![Generic badge](https://img.shields.io/badge/version-2.0.0-green.svg) 6 | 7 | ## How does it work? 8 | 9 | User registers directory aliases, for example: 10 | ```bash 11 | goto -r dev /home/iridakos/development 12 | ``` 13 | and then `cd`s to that directory with: 14 | ```bash 15 | goto dev 16 | ``` 17 | 18 | ![goto demo gif](https://github.com/iridakos/goto/raw/master/doc/goto.gif) 19 | 20 | ## goto completion 21 | 22 | `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: 23 | 24 | ```bash 25 | $ goto 26 | bc /etc/bash_completion.d 27 | dev /home/iridakos/development 28 | rubies /home/iridakos/.rvm/rubies 29 | ``` 30 | 31 | ## Installation 32 | 33 | ### Via script 34 | Clone the repository and run the install script as super user or root: 35 | ```bash 36 | git clone https://github.com/iridakos/goto.git 37 | cd goto 38 | sudo ./install 39 | ``` 40 | 41 | ### Manually 42 | Copy the file `goto.sh` somewhere in your filesystem and add a line in your `.zshrc` or `.bashrc` to source it. 43 | 44 | 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: 45 | 46 | ```bash 47 | source ~/goto.sh 48 | ``` 49 | 50 | ### macOS - Homebrew 51 | 52 | A formula named `goto` is available for the bash shell in macOS. 53 | ```bash 54 | brew install goto 55 | ``` 56 | 57 | ### Add colored output 58 | 59 | ```bash 60 | echo -e "\$include /etc/inputrc\nset colored-completion-prefix on" >> ~/.inputrc 61 | ``` 62 | 63 | **Note:** 64 | - you need to restart your shell after installation 65 | - you need to have the bash completion feature enabled for bash in macOS (see this [issue](https://github.com/iridakos/goto/issues/36)): 66 | - you can install it with `brew install bash-completion` in case you don't have it already 67 | 68 | ## Usage 69 | 70 | * [Change to an aliased directory](#change-to-an-aliased-directory) 71 | * [Register an alias](#register-an-alias) 72 | * [Unregister an alias](#unregister-an-alias) 73 | * [List aliases](#list-aliases) 74 | * [Expand an alias](#expand-an-alias) 75 | * [Cleanup](#cleanup) 76 | * [Help](#help) 77 | * [Version](#version) 78 | * [Extras](#extras) 79 | * [Push before changing directories](#push-before-changing-directories) 80 | * [Revert to a pushed directory](#revert-to-a-pushed-directory) 81 | * [Troubleshooting](#troubleshooting) 82 | * [Updating from 1.x to 2.x](#updating-from-1x-to-2x) 83 | * [zsh](#zsh) 84 | * [command not found compdef](#command-not-found-compdef) 85 | 86 | ### Change to an aliased directory 87 | To change to an aliased directory, type: 88 | ```bash 89 | goto 90 | ``` 91 | 92 | #### Example: 93 | ```bash 94 | goto dev 95 | ``` 96 | 97 | ### Register an alias 98 | To register a directory alias, type: 99 | ```bash 100 | goto -r 101 | ``` 102 | or 103 | ```bash 104 | goto --register 105 | ``` 106 | 107 | #### Example: 108 | ```bash 109 | goto -r blog /mnt/external/projects/html/blog 110 | ``` 111 | or 112 | ```bash 113 | goto --register blog /mnt/external/projects/html/blog 114 | ``` 115 | 116 | #### Notes 117 | 118 | * `goto` **expands** the directories hence you can easily alias your current directory with: 119 | ```bash 120 | goto -r last_release . 121 | ``` 122 | and it will automatically be aliased to the whole path. 123 | * Pressing the `tab` key after the alias name, you have the default directory suggestions by the shell. 124 | 125 | ### Unregister an alias 126 | 127 | To unregister an alias, use: 128 | ```bash 129 | goto -u 130 | ``` 131 | or 132 | ```bash 133 | goto --unregister 134 | ``` 135 | #### Example 136 | ``` 137 | goto -u last_release 138 | ``` 139 | or 140 | ``` 141 | goto --unregister last_release 142 | ``` 143 | 144 | #### Notes 145 | 146 | Pressing the `tab` key after the command (`-u` or `--unregister`), the completion script will prompt you with the list of registered aliases for your convenience. 147 | 148 | ### List aliases 149 | 150 | To get the list of your currently registered aliases, use: 151 | ```bash 152 | goto -l 153 | ``` 154 | or 155 | ```bash 156 | goto --list 157 | ``` 158 | 159 | ### Expand an alias 160 | 161 | To expand an alias to its value, use: 162 | ```bash 163 | goto -x 164 | ``` 165 | or 166 | ```bash 167 | goto --expand 168 | ``` 169 | 170 | #### Example 171 | ```bash 172 | goto -x last_release 173 | ``` 174 | or 175 | ```bash 176 | goto --expand last_release 177 | ``` 178 | 179 | ### Cleanup 180 | 181 | To cleanup the aliases from directories that are no longer accessible in your filesystem, use: 182 | 183 | ```bash 184 | goto -c 185 | ``` 186 | or 187 | ```bash 188 | goto --cleanup 189 | ``` 190 | 191 | ### Help 192 | 193 | To view the tool's help information, use: 194 | ```bash 195 | goto -h 196 | ``` 197 | or 198 | ```bash 199 | goto --help 200 | ``` 201 | 202 | ### Version 203 | 204 | To view the tool's version, use: 205 | ```bash 206 | goto -v 207 | ``` 208 | or 209 | ```bash 210 | goto --version 211 | ``` 212 | 213 | ## Extras 214 | 215 | ### Push before changing directories 216 | 217 | To first push the current directory onto the directory stack before changing directories, type: 218 | ```bash 219 | goto -p 220 | ``` 221 | or 222 | ```bash 223 | goto --push 224 | ``` 225 | 226 | ### Revert to a pushed directory 227 | To return to a pushed directory, type: 228 | ```bash 229 | goto -o 230 | ``` 231 | or 232 | ```bash 233 | goto --pop 234 | ``` 235 | 236 | #### Notes 237 | 238 | This command is equivalent to `popd`, but within the `goto` command. 239 | 240 | ## Troubleshooting 241 | 242 | ### Updating from 1.x to 2.x 243 | 244 | From version **2.x and after**, the `goto` DB file is located in the `$XDG_CONFIG_HOME` or in the `~/.config` directory under the name `goto`. 245 | 246 | If you updated from version **1.x** to **2.x or newer**, you need to move this file which was previously located at `~/.goto`. 247 | 248 | *Note that the new file is not hidden, it does not start with a dot `.`* 249 | 250 | ### zsh 251 | 252 | #### command not found: compdef 253 | 254 | In case you get such an error, you need to load the `bashcompinit`. Append this to your `.zshrc` file: 255 | ```bash 256 | autoload bashcompinit 257 | bashcompinit 258 | ``` 259 | 260 | ## TODO 261 | 262 | * ~~Test on macOS~~ extensively 263 | * Write [tests](https://github.com/iridakos/goto/issues/2) 264 | 265 | ## Contributing 266 | 267 | 1. Fork it ( https://github.com/iridakos/goto/fork ) 268 | 2. Create your feature branch (`git checkout -b my-new-feature`) 269 | 3. Commit your changes (`git commit -am 'Add some feature'`) 270 | 4. Push to the branch (`git push origin my-new-feature`) 271 | 5. Make sure that the script does not have errors or warning on [ShellCheck](https://www.shellcheck.net/) 272 | 6. Create a new Pull Request 273 | 274 | ## License 275 | 276 | This tool is open source under the [MIT License](https://opensource.org/licenses/MIT) terms. 277 | 278 | [[Back To Top]](#goto) 279 | -------------------------------------------------------------------------------- /goto.sh: -------------------------------------------------------------------------------- 1 | # shellcheck shell=bash 2 | # shellcheck disable=SC2039 3 | # SOURCE: https://github.com/iridakos/goto 4 | # MIT License 5 | # 6 | # Copyright (c) 2018 Lazarus Lazaridis 7 | # 8 | # Permission is hereby granted, free of charge, to any person obtaining a copy 9 | # of this software and associated documentation files (the "Software"), to deal 10 | # in the Software without restriction, including without limitation the rights 11 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | # copies of the Software, and to permit persons to whom the Software is 13 | # furnished to do so, subject to the following conditions: 14 | # 15 | # The above copyright notice and this permission notice shall be included in all 16 | # copies or substantial portions of the Software. 17 | # 18 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | # SOFTWARE. 25 | 26 | # Changes to the given alias directory 27 | # or executes a command based on the arguments. 28 | goto() 29 | { 30 | local target 31 | _goto_resolve_db 32 | 33 | if [ -z "$1" ]; then 34 | # display usage and exit when no args 35 | _goto_usage 36 | return 37 | fi 38 | 39 | subcommand="$1" 40 | shift 41 | case "$subcommand" in 42 | -c|--cleanup) 43 | _goto_cleanup "$@" 44 | ;; 45 | -r|--register) # Register an alias 46 | _goto_register_alias "$@" 47 | ;; 48 | -u|--unregister) # Unregister an alias 49 | _goto_unregister_alias "$@" 50 | ;; 51 | -p|--push) # Push the current directory onto the pushd stack, then goto 52 | _goto_directory_push "$@" 53 | ;; 54 | -o|--pop) # Pop the top directory off of the pushd stack, then change that directory 55 | _goto_directory_pop 56 | ;; 57 | -l|--list) 58 | _goto_list_aliases 59 | ;; 60 | -x|--expand) # Expand an alias 61 | _goto_expand_alias "$@" 62 | ;; 63 | -h|--help) 64 | _goto_usage 65 | ;; 66 | -v|--version) 67 | _goto_version 68 | ;; 69 | *) 70 | _goto_directory "$subcommand" 71 | ;; 72 | esac 73 | return $? 74 | } 75 | 76 | _goto_resolve_db() 77 | { 78 | local CONFIG_DEFAULT="${XDG_CONFIG_HOME:-$HOME/.config}/goto" 79 | GOTO_DB="${GOTO_DB:-$CONFIG_DEFAULT}" 80 | GOTO_DB_CONFIG_DIRNAME=$(dirname "$GOTO_DB") 81 | if [[ ! -d "$GOTO_DB_CONFIG_DIRNAME" ]]; then 82 | mkdir "$GOTO_DB_CONFIG_DIRNAME" 83 | fi 84 | touch -a "$GOTO_DB" 85 | } 86 | 87 | _goto_usage() 88 | { 89 | cat <<\USAGE 90 | usage: goto [