feat: Bump version to 0.2, see Changelog in README
This commit is contained in:
parent
31b8228fd8
commit
1eed56422a
56
README
56
README
@ -1,31 +1,31 @@
|
|||||||
****
|
********
|
||||||
GOTO
|
G (GOTO)
|
||||||
****
|
********
|
||||||
|
|
||||||
A faster way to cd to commonly used directories inspired by commacd. Tested on
|
A faster way to cd to commonly used directories. Inspired by commacd. Tested on
|
||||||
Bash 5.1, but should work on most versions.
|
Bash 5.1, but should work on most versions.
|
||||||
|
|
||||||
Installation
|
Installation
|
||||||
************
|
************
|
||||||
|
|
||||||
On most operatin systems with Bash run:
|
On most operatin systems with Bash run::
|
||||||
|
|
||||||
$ curl -o ~/.goto.sh \
|
$ curl -o ~/.goto.sh \
|
||||||
-sSL https://gitea.gch.icu/ge/goto/raw/branch/master/goto.sh
|
-sSL https://gitea.gch.icu/ge/goto/raw/branch/master/goto.sh
|
||||||
$ echo '[ -f ~/.goto.sh ] && . ~/.goto.sh' >> ~/.bashrc
|
$ echo '[ -f ~/.goto.sh ] && . ~/.goto.sh' >> ~/.bashrc
|
||||||
|
|
||||||
Reread ~/.bashrc by command:
|
Reread ~/.bashrc by command::
|
||||||
|
|
||||||
$ source ~/.bashrc
|
$ source ~/.bashrc
|
||||||
|
|
||||||
Usage
|
Usage
|
||||||
*****
|
*****
|
||||||
|
|
||||||
Available commands (actually is aliases to functions):
|
Available commands (actually is aliases to functions)::
|
||||||
|
|
||||||
s [<path>] bookmark $PWD or <path> (save into ~/.gotosave).
|
g [<pattern>] goto directory. If you have single bookmark dir will be
|
||||||
g [<pattern>] goto directory. If you have only one bookmark dir will be
|
|
||||||
changed without prompt. Type dir number in prompt to cd.
|
changed without prompt. Type dir number in prompt to cd.
|
||||||
|
g-save [<path>] bookmark $PWD or <path> (save into ~/.goto_saved).
|
||||||
|
|
||||||
Run `g` to show the entire list of bookmarks and select the one you need.
|
Run `g` to show the entire list of bookmarks and select the one you need.
|
||||||
|
|
||||||
@ -43,16 +43,16 @@ It works in a similar way.
|
|||||||
Examples
|
Examples
|
||||||
--------
|
--------
|
||||||
|
|
||||||
Previously set up your commonly used dirs. Specify dir as argument:
|
Previously set up your commonly used dirs. Specify dir as argument::
|
||||||
|
|
||||||
$ s ~/Documents
|
$ g-save ~/Documents
|
||||||
$ s ~/Downloads
|
$ g-save ~/Downloads
|
||||||
|
|
||||||
or cd into dir and simply run
|
or cd into dir and simply run::
|
||||||
|
|
||||||
$ s
|
$ g-save
|
||||||
|
|
||||||
Goto directory by number:
|
Go to directory by number::
|
||||||
|
|
||||||
$ g
|
$ g
|
||||||
0 ~/Documents/
|
0 ~/Documents/
|
||||||
@ -60,33 +60,45 @@ Goto directory by number:
|
|||||||
: <type number here, e.g. 1>
|
: <type number here, e.g. 1>
|
||||||
=> cd /home/user/Downloads
|
=> cd /home/user/Downloads
|
||||||
|
|
||||||
Goto '~/Downloads' directory by regex:
|
Goto '~/Downloads' directory by regex::
|
||||||
|
|
||||||
$ g w
|
$ g w
|
||||||
=> cd /home/user/Downloads
|
=> cd /home/user/Downloads
|
||||||
|
|
||||||
Another way :)
|
Another way :)::
|
||||||
|
|
||||||
$ g 'do[^c]'
|
$ g 'do[^c]'
|
||||||
=> cd /home/gd/Downloads
|
=> cd /home/gd/Downloads
|
||||||
|
|
||||||
and etc.
|
and etc.
|
||||||
|
|
||||||
|
Changelog
|
||||||
|
*********
|
||||||
|
|
||||||
|
06 Feb 2022
|
||||||
|
- `~/.gotosave` renamed to `~/.goto_saved`
|
||||||
|
- Alias `s` changed to `g-save`
|
||||||
|
|
||||||
|
07 Jan 2022
|
||||||
|
Initial release.
|
||||||
|
|
||||||
Tips
|
Tips
|
||||||
****
|
****
|
||||||
|
|
||||||
Combining commacd, goto and Bash autocd option gives a great experience!
|
Combining `commacd`, `g` and Bash ``autocd`` option gives a great experience!
|
||||||
|
|
||||||
|
Add to you ~/.bashrc following line::
|
||||||
|
|
||||||
Add to you ~/.bashrc following:
|
|
||||||
shopt -s autocd
|
shopt -s autocd
|
||||||
|
|
||||||
Now you can type just directory name without 'cd' to change directory.
|
Now you can type just directory name without 'cd' to change directory.
|
||||||
|
|
||||||
Get commacd here: https://github.com/shyiko/commacd
|
Get `commacd` here: https://github.com/shyiko/commacd
|
||||||
|
|
||||||
Alternatives?
|
Alternatives?
|
||||||
*************
|
*************
|
||||||
|
|
||||||
Some goto alternatives:
|
Some `g` alternatives:
|
||||||
|
|
||||||
- aliases (yep, Bash aliases)
|
- aliases (yep, Bash builtin aliases)
|
||||||
- https://github.com/huyng/bashmarks
|
- https://github.com/huyng/bashmarks
|
||||||
|
24
goto.sh
24
goto.sh
@ -1,5 +1,5 @@
|
|||||||
# * goto (goto directory) - bookmark directorie in Bash.
|
# * g (goto directory) - bookmark directories in Bash.
|
||||||
# * versuion: 0.1
|
# * versuion: 0.2
|
||||||
|
|
||||||
# This is free and unencumbered software released into the public domain.
|
# This is free and unencumbered software released into the public domain.
|
||||||
#
|
#
|
||||||
@ -45,13 +45,13 @@ _goto_cd() {
|
|||||||
_goto_prompt() {
|
_goto_prompt() {
|
||||||
##### Prompt and cd #####
|
##### Prompt and cd #####
|
||||||
|
|
||||||
# Exit if no dirs in ~/.gotosave
|
# Exit if no dirs in ~/.goto_saved
|
||||||
if [ "${#dirs[@]}" -eq 0 ] || [[ "${dirs[@]}" == '' ]]; then
|
if [ "${#dirs[@]}" -eq 0 ] || [[ "${dirs[@]}" == '' ]]; then
|
||||||
echo goto: nothing to do; return 1
|
echo goto: nothing to do; return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# cd into dir without prompt if you have single directory
|
# cd into dir without prompt if you have single directory
|
||||||
# in ~/.gotosave
|
# in ~/.goto_saved
|
||||||
if [ "${#dirs[@]}" -eq 1 ]; then
|
if [ "${#dirs[@]}" -eq 1 ]; then
|
||||||
_goto_cd "${dirs[@]}" && return 0
|
_goto_cd "${dirs[@]}" && return 0
|
||||||
fi
|
fi
|
||||||
@ -84,7 +84,7 @@ _goto_prompt() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_goto_search() {
|
_goto_search() {
|
||||||
grep -iP "$1" ~/.gotosave
|
grep -iP "$1" ~/.goto_saved
|
||||||
}
|
}
|
||||||
|
|
||||||
_goto() {
|
_goto() {
|
||||||
@ -92,13 +92,13 @@ _goto() {
|
|||||||
|
|
||||||
# Get directory list ('dirs' array)
|
# Get directory list ('dirs' array)
|
||||||
dirs=()
|
dirs=()
|
||||||
if [ -f ~/.gotosave ]; then
|
if [ -f ~/.goto_saved ]; then
|
||||||
if [ "$1" ]; then
|
if [ "$1" ]; then
|
||||||
# Search dirs with Perl regex
|
# Search dirs with Perl regex
|
||||||
_source="$(_goto_search "$1")"
|
_source="$(_goto_search "$1")"
|
||||||
else
|
else
|
||||||
# Load all directories
|
# Load all directories
|
||||||
_source="$(<~/.gotosave)"
|
_source="$(<~/.goto_saved)"
|
||||||
fi
|
fi
|
||||||
while read -r dir; do
|
while read -r dir; do
|
||||||
dirs+=("$dir")
|
dirs+=("$dir")
|
||||||
@ -109,7 +109,7 @@ _goto() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_goto_save() {
|
_goto_save() {
|
||||||
##### Save PWD or 1 to ~/.gotosave file #####
|
##### Save PWD or 1 to ~/.goto_saved file #####
|
||||||
|
|
||||||
local dir
|
local dir
|
||||||
if [ "$1" ]; then
|
if [ "$1" ]; then
|
||||||
@ -118,13 +118,13 @@ _goto_save() {
|
|||||||
dir="$PWD"
|
dir="$PWD"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Exit if directory is already in ~/.gotosave
|
# Exit if directory is already in ~/.goto_saved
|
||||||
if grep "^${dir%%+(/)}\$" ~/.gotosave > /dev/null; then
|
if grep "^${dir%%+(/)}\$" ~/.goto_saved > /dev/null; then
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Save directory
|
# Save directory
|
||||||
if echo "${dir%%+(/)}" >> ~/.gotosave; then
|
if echo "${dir%%+(/)}" >> ~/.goto_saved; then
|
||||||
echo "$dir"
|
echo "$dir"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@ -139,4 +139,4 @@ _goto_complete() {
|
|||||||
complete -F _goto_complete g
|
complete -F _goto_complete g
|
||||||
|
|
||||||
alias g='_goto'
|
alias g='_goto'
|
||||||
alias s='_goto_save'
|
alias g-save='_goto_save'
|
||||||
|
Loading…
Reference in New Issue
Block a user