mirror of
https://github.com/iridakos/goto.git
synced 2025-05-18 00:10:13 -07:00
I also made the documentation and name of file more generic as it works for both zsh and bash. I removed the shebang since this file is simply sourced by the calling shell and it doesn't have executable permissions anyway. The various functions were updated to return non-zero on errors in case anyone uses goto in other scripts. The logic for parsing ~/.goto to determine which aliases can be cleaned was simplified into an awk script that removed the array manipulation logic that was not zsh compatible.
165 lines
3.1 KiB
Markdown
165 lines
3.1 KiB
Markdown
# goto
|
|
|
|
`goto` is a shell utility allowing users to change faster to aliased directories supporting auto-completion :feet:
|
|
|
|
## How does it work?
|
|
|
|
User registers directory aliases, for example:
|
|
```bash
|
|
goto -r dev /home/iridakos/development
|
|
```
|
|
and then `cd`s to that directory with:
|
|
```bash
|
|
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 or zsh prompts with suggestions of the available aliases:
|
|
|
|
```bash
|
|
$ goto <tab>
|
|
bc /etc/bash_completion.d
|
|
dev /home/iridakos/development
|
|
rubies /home/iridakos/.rvm/rubies
|
|
```
|
|
|
|
## Installation
|
|
|
|
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.sh
|
|
```
|
|
|
|
## Usage
|
|
|
|
### Change to an aliased directory
|
|
To change to an aliased directory, type:
|
|
```bash
|
|
goto <alias>
|
|
```
|
|
|
|
#### Example:
|
|
```bash
|
|
goto dev
|
|
```
|
|
|
|
### Register an alias
|
|
To register a directory alias, type:
|
|
```bash
|
|
goto -r <alias> <directory>
|
|
```
|
|
or
|
|
```bash
|
|
goto --register <alias> <directory>
|
|
```
|
|
|
|
#### Example:
|
|
```bash
|
|
goto -r blog /mnt/external/projects/html/blog
|
|
```
|
|
or
|
|
```bash
|
|
goto --register blog /mnt/external/projects/html/blog
|
|
```
|
|
|
|
#### Notes
|
|
|
|
* `goto` **expands** the directories hence you can easily alias your current directory with:
|
|
```bash
|
|
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 the shell.
|
|
|
|
### Unregister an alias
|
|
|
|
To unregister an alias, use:
|
|
```bash
|
|
goto -u <alias>
|
|
```
|
|
or
|
|
```bash
|
|
goto --unregister <alias>
|
|
```
|
|
#### Example
|
|
```
|
|
goto -u last_release
|
|
```
|
|
or
|
|
```
|
|
goto --unregister last_release
|
|
```
|
|
|
|
#### Notes
|
|
|
|
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.
|
|
|
|
### List aliases
|
|
|
|
To get the list of your currently registered aliases, use:
|
|
```bash
|
|
goto -l
|
|
```
|
|
or
|
|
```bash
|
|
goto --list
|
|
```
|
|
|
|
### Cleanup
|
|
|
|
To cleanup the aliases from directories that are no longer accessible in your filesystem, use:
|
|
|
|
```bash
|
|
goto -c
|
|
```
|
|
or
|
|
```bash
|
|
goto --cleanup
|
|
```
|
|
|
|
### Help
|
|
|
|
To view the tool's help information, use:
|
|
```bash
|
|
goto -h
|
|
```
|
|
or
|
|
```bash
|
|
goto --help
|
|
```
|
|
|
|
### Version
|
|
|
|
To view the tool's version, use:
|
|
```bash
|
|
goto -v
|
|
```
|
|
or
|
|
```bash
|
|
goto --version
|
|
```
|
|
|
|
## TODO
|
|
|
|
* ~~Test on macOS~~ extensively
|
|
* Write [tests](https://github.com/iridakos/goto/issues/2)
|
|
|
|
## Contributing
|
|
|
|
1. Fork it ( https://github.com/iridakos/goto/fork )
|
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
4. Push to the branch (`git push origin my-new-feature`)
|
|
5. Make sure that the script does not have errors or warning on [ShellCheck](https://www.shellcheck.net/)
|
|
6. Create a new Pull Request
|
|
|
|
## License
|
|
|
|
This tool is open source under the [MIT License](https://opensource.org/licenses/MIT) terms.
|