You are not logged in.
This
export BMDB="${XDG_CONFIG_HOME}/bm"
bm()
{
if [[ -z $1 ]]; then
return 0
elif [[ $1 != '.' || $1 != '..' ]]; then
echo "$1"
return 0
fi
[[ -d "$BMDB" ]] || mkdir -p "$BMDB"
case $1 in
+*)
if [[ "${2:0:1}" == "/" ]]; then
echo "$BMDB/${1:1} -> $2"
ln -s "$2" "$BMDB/${1:1}"
else
echo "$BMDB/${1:1} -> $PWD/$2"
ln -s "$PWD/$2" "$BMDB/${1:1}"
fi
;;
-*)
rm -f "$BMDB/${1:1}"
;;
*)
if [[ -h "$BMDB/$1" ]]; then
readlink "$BMDB/$1"
elif [[ -e "$BMDB/$1" ]]; then
local answer
read -p "$1 is an invalid bookmark, would you like to delete it? [Y/n] " answer
[[ $(tr [:upper:] [:lower:] <<<${answer:0:1}) != n ]] && rm -f "$BMDB/$1"
else
echo "$1"
return 1
fi
;;
esac
}
_cd()
{
local path="$(bm "$@")"
if [[ -z $path ]]; then
builtin cd
else
builtin cd "$path"
fi
}
alias cd="_cd"
works fine without problems from my initial testing, the only problem I'm having is that tab-completion is completely broken.
Any ideas on how to fix it?
Offline
You've redefined _cd(), which is a completion function defined by the bash_completion package, see:
$ complete -p cd
$ type _cd
You don't need the "cd" alias here. Just call the function "cd" instead of "_cd".
Offline
Btw, you can't rely on XDG_* variables to be defined in the environment. use
BMDB="${XDG_CONFIG_HOME:-$HOME/.config}/bm"
To use the default value $HOME/.config if XDG_CONFIG_HOME is not set or empty.
Offline
I'm sorry to not contribute anything to your function but have you thought about using ZSH? pushd and popd do exactly what you are trying to do. cd - opens a menu of previously visited sites and completion works, too, of course.
no place like /home
github
Offline
[[ $(tr [:upper:] [:lower:] <<<${answer:0:1}) != n ]] && rm -f "$BMDB/$1"
Here you want shopt -s nocasematch, or a simplified regex:
[[ answer =~ ^[Nn] ]] || rm -f "$BMDB/$1"
edit:
A more interesting reason behind why you shouldn't use that tr(1) line:
$ touch :; echo [:upper:] [:lower:]
: :
Last edited by andresp (2010-06-13 09:53:28)
Offline
Thanks for the replies, it works now.
Offline