v0.4
This commit is contained in:
parent
19860fe8db
commit
e7ce1c198f
4
README
4
README
@ -67,6 +67,10 @@ and etc.
|
|||||||
Changelog
|
Changelog
|
||||||
=========
|
=========
|
||||||
|
|
||||||
|
v0.4 (05 Oct 2022)
|
||||||
|
|
||||||
|
* Fix parsing paths
|
||||||
|
|
||||||
v0.3 (05 Oct 2022)
|
v0.3 (05 Oct 2022)
|
||||||
|
|
||||||
* Refactored, added POSIX-compatibility
|
* Refactored, added POSIX-compatibility
|
||||||
|
22
g.sh
22
g.sh
@ -1,5 +1,5 @@
|
|||||||
# * g (goto directory) - bookmark directories in shell.
|
# * g (goto directory) - bookmark directories in shell.
|
||||||
# * version: 0.3
|
# * version: 0.4
|
||||||
|
|
||||||
# This is free and unencumbered software released into the public domain.
|
# This is free and unencumbered software released into the public domain.
|
||||||
#
|
#
|
||||||
@ -42,17 +42,16 @@ _g_cd() {
|
|||||||
printf 'g: no such directory %s\n' "$1" >&2
|
printf 'g: no such directory %s\n' "$1" >&2
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
if cd -- "$1" > /dev/null; then
|
_dir="$(echo "$1" | sed "s%^~%$HOME%;s%//%/%g")"
|
||||||
echo "$1"
|
if cd -- "$_dir" > /dev/null; then
|
||||||
|
echo "$_dir"
|
||||||
else
|
else
|
||||||
printf '\bg: cannot cd into %s\n' "$1" >&2
|
printf '\bg: cannot cd into %s\n' "$_dir" >&2
|
||||||
fi
|
fi
|
||||||
return "$?"
|
return "$?"
|
||||||
}
|
}
|
||||||
|
|
||||||
_g_prompt() {
|
_g_prompt() {
|
||||||
# Prompt and cd
|
|
||||||
|
|
||||||
# Exit if no dirs in $_g_file
|
# Exit if no dirs in $_g_file
|
||||||
if [ "$#" -eq 0 ] || [ "$*" = '' ]; then
|
if [ "$#" -eq 0 ] || [ "$*" = '' ]; then
|
||||||
echo goto: nothing to do; return 1
|
echo goto: nothing to do; return 1
|
||||||
@ -99,8 +98,7 @@ _g_search() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_g() {
|
_g() {
|
||||||
# Main function
|
# Get dirs from $_g_file
|
||||||
# Get directory list ('dirs' array)
|
|
||||||
if [ -f "$_g_file" ]; then
|
if [ -f "$_g_file" ]; then
|
||||||
if [ "$1" ]; then
|
if [ "$1" ]; then
|
||||||
# Search dirs with Perl regex
|
# Search dirs with Perl regex
|
||||||
@ -116,9 +114,13 @@ _g() {
|
|||||||
|
|
||||||
_g_save() {
|
_g_save() {
|
||||||
# Save dir in $_g_file
|
# Save dir in $_g_file
|
||||||
|
|
||||||
if [ -n "$1" ]; then
|
if [ -n "$1" ]; then
|
||||||
_dir="$1"
|
if hash realpath >/dev/null 2>&1; then
|
||||||
|
_dir="$(realpath "$1")"
|
||||||
|
else
|
||||||
|
_dir="$(echo "${PWD}/${1%*/}" | sed 's%//%/%g')"
|
||||||
|
[ -d "$_dir" ] || _dir="$1"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
_dir="$PWD"
|
_dir="$PWD"
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user