Skip to content

Commit

Permalink
lunar: improve lcd alias
Browse files Browse the repository at this point in the history
This now checks whether the section really exists
before trying to cd there. This removes ugly "$MOONBASE//$MODULE"
folder does not exist error message
  • Loading branch information
v4hn committed Nov 16, 2013
1 parent 847d816 commit 737f666
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions system/lunar/profile.d/lunar.rc
Expand Up @@ -171,10 +171,19 @@ alias lwtf="lvu what"
complete -F _lunar_comp_modules lwtf

function lcd(){
[[ -z "$1" || "$1" = "." ]] &&
cd "$(lsh 'echo $MOONBASE')" ||
cd "$(lsh "echo \$MOONBASE/\$(find_section $1)/$1")"
return 0
local mb section
mb="$(lsh 'echo $MOONBASE')"
if [[ -z "$1" || "$1" = "." ]]; then
cd "$mb"
else
section="$(lsh find_section "$1")"
if [[ -z "$section" ]]; then
echo "$0: lcd: No such module in moonbase" >&2
return 1
else
cd "$mb/$section/$1"
fi
fi
}
complete -F _lunar_comp_modules lcd

Expand Down

0 comments on commit 737f666

Please sign in to comment.