2022-02-06 17:31:25 +03:00
|
|
|
********
|
|
|
|
G (GOTO)
|
|
|
|
********
|
2022-01-07 20:10:17 +03:00
|
|
|
|
2022-02-06 17:31:25 +03:00
|
|
|
A faster way to cd to commonly used directories. Inspired by commacd. Tested on
|
2022-01-07 20:10:17 +03:00
|
|
|
Bash 5.1, but should work on most versions.
|
|
|
|
|
|
|
|
Installation
|
|
|
|
************
|
|
|
|
|
2022-02-06 17:31:25 +03:00
|
|
|
On most operatin systems with Bash run::
|
2022-01-07 20:10:17 +03:00
|
|
|
|
|
|
|
$ curl -o ~/.goto.sh \
|
|
|
|
-sSL https://gitea.gch.icu/ge/goto/raw/branch/master/goto.sh
|
|
|
|
$ echo '[ -f ~/.goto.sh ] && . ~/.goto.sh' >> ~/.bashrc
|
|
|
|
|
2022-02-06 17:31:25 +03:00
|
|
|
Reread ~/.bashrc by command::
|
2022-01-07 20:10:17 +03:00
|
|
|
|
|
|
|
$ source ~/.bashrc
|
|
|
|
|
|
|
|
Usage
|
|
|
|
*****
|
|
|
|
|
2022-02-06 17:31:25 +03:00
|
|
|
Available commands (actually is aliases to functions)::
|
2022-01-07 20:10:17 +03:00
|
|
|
|
2022-02-06 17:31:25 +03:00
|
|
|
g [<pattern>] goto directory. If you have single bookmark dir will be
|
|
|
|
changed without prompt. Type dir number in prompt to cd.
|
|
|
|
g-save [<path>] bookmark $PWD or <path> (save into ~/.goto_saved).
|
2022-01-07 20:10:17 +03:00
|
|
|
|
|
|
|
Run `g` to show the entire list of bookmarks and select the one you need.
|
|
|
|
|
|
|
|
You don't even need to press `Enter` to confirm your selection -- just type in
|
|
|
|
the bookmark number. The exception is when you have a two-digit number (or more)
|
|
|
|
and you select a bookmark whose number is less than 10. Then you have to press
|
|
|
|
`Enter`.
|
|
|
|
|
|
|
|
You can pass the Perl regular expression (processed by grep -Pi) as an for 'g'.
|
|
|
|
At the same time, if only one bookmark is found, then the directory will be
|
|
|
|
changed directly to it. If there are several bookmarks, you will be prompted to
|
|
|
|
choose the appropriate one. Also you can use autocompletion by pressing `Tab`.
|
|
|
|
It works in a similar way.
|
|
|
|
|
|
|
|
Examples
|
|
|
|
--------
|
|
|
|
|
2022-02-06 17:31:25 +03:00
|
|
|
Previously set up your commonly used dirs. Specify dir as argument::
|
2022-01-07 20:10:17 +03:00
|
|
|
|
2022-02-06 17:31:25 +03:00
|
|
|
$ g-save ~/Documents
|
|
|
|
$ g-save ~/Downloads
|
2022-01-07 20:10:17 +03:00
|
|
|
|
2022-02-06 17:31:25 +03:00
|
|
|
or cd into dir and simply run::
|
2022-01-07 20:10:17 +03:00
|
|
|
|
2022-02-06 17:31:25 +03:00
|
|
|
$ g-save
|
2022-01-07 20:10:17 +03:00
|
|
|
|
2022-02-06 17:31:25 +03:00
|
|
|
Go to directory by number::
|
2022-01-07 20:10:17 +03:00
|
|
|
|
|
|
|
$ g
|
|
|
|
0 ~/Documents/
|
|
|
|
1 ~/Downloads/
|
|
|
|
: <type number here, e.g. 1>
|
|
|
|
=> cd /home/user/Downloads
|
|
|
|
|
2022-02-06 17:31:25 +03:00
|
|
|
Goto '~/Downloads' directory by regex::
|
2022-01-07 20:10:17 +03:00
|
|
|
|
|
|
|
$ g w
|
|
|
|
=> cd /home/user/Downloads
|
|
|
|
|
2022-02-06 17:31:25 +03:00
|
|
|
Another way :)::
|
2022-01-07 20:10:17 +03:00
|
|
|
|
|
|
|
$ g 'do[^c]'
|
|
|
|
=> cd /home/gd/Downloads
|
|
|
|
|
|
|
|
and etc.
|
|
|
|
|
2022-02-06 17:31:25 +03:00
|
|
|
Changelog
|
|
|
|
*********
|
|
|
|
|
|
|
|
06 Feb 2022
|
|
|
|
- `~/.gotosave` renamed to `~/.goto_saved`
|
|
|
|
- Alias `s` changed to `g-save`
|
|
|
|
|
|
|
|
07 Jan 2022
|
|
|
|
Initial release.
|
|
|
|
|
2022-01-07 20:10:17 +03:00
|
|
|
Tips
|
|
|
|
****
|
|
|
|
|
2022-02-06 17:31:25 +03:00
|
|
|
Combining `commacd`, `g` and Bash ``autocd`` option gives a great experience!
|
|
|
|
|
|
|
|
Add to you ~/.bashrc following line::
|
2022-01-07 20:10:17 +03:00
|
|
|
|
|
|
|
shopt -s autocd
|
2022-02-06 17:31:25 +03:00
|
|
|
|
2022-01-07 20:10:17 +03:00
|
|
|
Now you can type just directory name without 'cd' to change directory.
|
|
|
|
|
2022-02-06 17:31:25 +03:00
|
|
|
Get `commacd` here: https://github.com/shyiko/commacd
|
2022-01-07 20:10:17 +03:00
|
|
|
|
|
|
|
Alternatives?
|
|
|
|
*************
|
|
|
|
|
2022-02-06 17:31:25 +03:00
|
|
|
Some `g` alternatives:
|
2022-01-07 20:10:17 +03:00
|
|
|
|
2022-02-06 17:31:25 +03:00
|
|
|
- aliases (yep, Bash builtin aliases)
|
2022-01-07 20:10:17 +03:00
|
|
|
- https://github.com/huyng/bashmarks
|