feat: Bump version to 0.2, see Changelog in README

This commit is contained in:
ge 2022-02-06 17:31:25 +03:00
parent 31b8228fd8
commit 1eed56422a
2 changed files with 47 additions and 35 deletions

58
README
View File

@ -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.
Installation
************
On most operatin systems with Bash run:
On most operatin systems with Bash run::
$ curl -o ~/.goto.sh \
-sSL https://gitea.gch.icu/ge/goto/raw/branch/master/goto.sh
$ echo '[ -f ~/.goto.sh ] && . ~/.goto.sh' >> ~/.bashrc
Reread ~/.bashrc by command:
Reread ~/.bashrc by command::
$ source ~/.bashrc
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 only one bookmark dir will be
changed without prompt. Type dir number in prompt to cd.
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).
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
--------
Previously set up your commonly used dirs. Specify dir as argument:
Previously set up your commonly used dirs. Specify dir as argument::
$ s ~/Documents
$ s ~/Downloads
$ g-save ~/Documents
$ 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
0 ~/Documents/
@ -60,33 +60,45 @@ Goto directory by number:
: <type number here, e.g. 1>
=> cd /home/user/Downloads
Goto '~/Downloads' directory by regex:
Goto '~/Downloads' directory by regex::
$ g w
=> cd /home/user/Downloads
Another way :)
Another way :)::
$ g 'do[^c]'
=> cd /home/gd/Downloads
and etc.
Changelog
*********
06 Feb 2022
- `~/.gotosave` renamed to `~/.goto_saved`
- Alias `s` changed to `g-save`
07 Jan 2022
Initial release.
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
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?
*************
Some goto alternatives:
Some `g` alternatives:
- aliases (yep, Bash aliases)
- aliases (yep, Bash builtin aliases)
- https://github.com/huyng/bashmarks

24
goto.sh
View File

@ -1,5 +1,5 @@
# * goto (goto directory) - bookmark directorie in Bash.
# * versuion: 0.1
# * g (goto directory) - bookmark directories in Bash.
# * versuion: 0.2
# This is free and unencumbered software released into the public domain.
#
@ -45,13 +45,13 @@ _goto_cd() {
_goto_prompt() {
##### Prompt and cd #####
# Exit if no dirs in ~/.gotosave
# Exit if no dirs in ~/.goto_saved
if [ "${#dirs[@]}" -eq 0 ] || [[ "${dirs[@]}" == '' ]]; then
echo goto: nothing to do; return 1
fi
# cd into dir without prompt if you have single directory
# in ~/.gotosave
# in ~/.goto_saved
if [ "${#dirs[@]}" -eq 1 ]; then
_goto_cd "${dirs[@]}" && return 0
fi
@ -84,7 +84,7 @@ _goto_prompt() {
}
_goto_search() {
grep -iP "$1" ~/.gotosave
grep -iP "$1" ~/.goto_saved
}
_goto() {
@ -92,13 +92,13 @@ _goto() {
# Get directory list ('dirs' array)
dirs=()
if [ -f ~/.gotosave ]; then
if [ -f ~/.goto_saved ]; then
if [ "$1" ]; then
# Search dirs with Perl regex
_source="$(_goto_search "$1")"
else
# Load all directories
_source="$(<~/.gotosave)"
_source="$(<~/.goto_saved)"
fi
while read -r dir; do
dirs+=("$dir")
@ -109,7 +109,7 @@ _goto() {
}
_goto_save() {
##### Save PWD or 1 to ~/.gotosave file #####
##### Save PWD or 1 to ~/.goto_saved file #####
local dir
if [ "$1" ]; then
@ -118,13 +118,13 @@ _goto_save() {
dir="$PWD"
fi
# Exit if directory is already in ~/.gotosave
if grep "^${dir%%+(/)}\$" ~/.gotosave > /dev/null; then
# Exit if directory is already in ~/.goto_saved
if grep "^${dir%%+(/)}\$" ~/.goto_saved > /dev/null; then
return 1
fi
# Save directory
if echo "${dir%%+(/)}" >> ~/.gotosave; then
if echo "${dir%%+(/)}" >> ~/.goto_saved; then
echo "$dir"
fi
}
@ -139,4 +139,4 @@ _goto_complete() {
complete -F _goto_complete g
alias g='_goto'
alias s='_goto_save'
alias g-save='_goto_save'