g/README

106 lines
2.4 KiB
Plaintext
Raw Normal View History

A faster way to cd to commonly used directories. Inspired by commacd. Tested on
2022-10-05 23:27:24 +03:00
Bash and Dash.
2022-01-07 20:10:17 +03:00
Installation
2022-10-05 23:27:24 +03:00
============
2022-01-07 20:10:17 +03:00
2022-10-05 23:27:24 +03:00
On most operatin systems with Bash run:
2022-01-07 20:10:17 +03:00
2022-10-05 23:27:24 +03:00
$ curl -o ~/.g.sh -sSL https://git.nxhs.cloud/ge/g/raw/branch/master/g.sh
$ echo '[ -f ~/.g.sh ] && . ~/.g.sh' >> ~/.bashrc
2022-01-07 20:10:17 +03:00
$ source ~/.bashrc
Usage
2022-10-05 23:27:24 +03:00
=====
2022-01-07 20:10:17 +03:00
2022-10-05 23:27:24 +03:00
Available commands (actually is aliases to functions):
2022-01-07 20:10:17 +03:00
g [<pattern>] goto directory. If you have single bookmark dir will be
changed without prompt. Type dir number in prompt to cd.
2022-10-05 23:27:24 +03:00
g_save [<path>] bookmark $PWD or <path> (save into ~/.g).
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`.
2022-10-05 23:27:24 +03:00
You can pass the Perl regular expression (processed by grep -Pi) as an for `g`.
2022-01-07 20:10:17 +03:00
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
2022-10-05 23:27:24 +03:00
choose the appropriate one. Also you can use autocompletion by pressing Tab.
2022-01-07 20:10:17 +03:00
It works in a similar way.
Examples
--------
Previously set up your commonly used dirs. Specify dir as argument::
2022-01-07 20:10:17 +03:00
2022-10-05 23:27:24 +03:00
$ g_save ~/Documents
$ g_save ~/Downloads
2022-01-07 20:10:17 +03:00
or cd into dir and simply run::
2022-01-07 20:10:17 +03:00
2022-10-05 23:27:24 +03:00
$ g_save
2022-01-07 20:10:17 +03:00
2022-10-05 23:27:24 +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>
2022-10-05 23:27:24 +03:00
=> cd /home/ge/Downloads
2022-01-07 20:10:17 +03:00
2022-10-05 23:27:24 +03:00
Goto '~/Downloads' directory by regex:
2022-01-07 20:10:17 +03:00
$ g w
2022-10-05 23:27:24 +03:00
=> cd /home/ge/Downloads
2022-01-07 20:10:17 +03:00
2022-10-05 23:27:24 +03:00
Another way:
2022-01-07 20:10:17 +03:00
$ g 'do[^c]'
2022-10-05 23:27:24 +03:00
=> cd /home/ge/Downloads
2022-01-07 20:10:17 +03:00
and etc.
Changelog
2022-10-05 23:27:24 +03:00
=========
2022-10-05 23:49:50 +03:00
v0.4 (05 Oct 2022)
* Fix parsing paths
2022-10-05 23:27:24 +03:00
v0.3 (05 Oct 2022)
2022-10-05 23:27:24 +03:00
* Refactored, added POSIX-compatibility
* Script renamed to `g.sh`
* ~/.goto_saved renamed to ~/.g
* Alias `g-save` changed to `g_save`
* Functions renamed
2022-10-05 23:27:24 +03:00
v0.2 (06 Feb 2022)
* ~/.gotosave renamed to ~/.goto_saved
* Alias `s` changed to `g-save`
2022-01-07 20:10:17 +03:00
2022-10-05 23:27:24 +03:00
v0.1 (07 Jan 2022)
2022-10-05 23:27:24 +03:00
Initial release.
2022-01-07 20:10:17 +03:00
2022-10-05 23:27:24 +03:00
Tips
====
2022-10-05 23:27:24 +03:00
Combining `commacd`, `g` and Bash ``shopt -s autocd`` option gives a great
experience!
2022-01-07 20:10:17 +03:00
Get `commacd` here: https://github.com/shyiko/commacd
2022-01-07 20:10:17 +03:00
Alternatives?
2022-10-05 23:27:24 +03:00
=============
2022-01-07 20:10:17 +03:00
Some `g` alternatives:
2022-01-07 20:10:17 +03:00
2022-10-05 23:27:24 +03:00
* aliases (yep, Bash builtin aliases)
* https://github.com/huyng/bashmarks