Merge pull request #114 from oh-my-fish/omf-cd-namespaced

Simplify `omf cd` code
This commit is contained in:
Bruno 2015-10-12 21:01:46 +01:00
commit dc8ec2ec1d
3 changed files with 24 additions and 27 deletions

View File

@ -1,25 +0,0 @@
# SYNOPSIS
# Change the current working directory to plugin / theme home directory.
#
# OPTIONS
# <name> Name of the package or theme.
function omf.cd -a name -d "Change the current working directory to plugin / theme home directory."
if test -z $name
pushd $OMF_PATH
return 0
end
if test -e $OMF_CONFIG/pkg/$name
pushd $OMF_CONFIG/pkg/$name
else if test -e $OMF_CONFIG/themes/$name
pushd $OMF_CONFIG/themes/$name
else if test -e $OMF_PATH/pkg/$name
pushd $OMF_PATH/pkg/$name
else if test -e $OMF_PATH/themes/$name
pushd $OMF_PATH/themes/$name
else
echo (omf::err)"$name is not a valid package/theme name"(omf::off) 1^&2
return $OMF_INVALID_ARG
end
end

View File

@ -0,0 +1,22 @@
# SYNOPSIS
# Change the current working directory to plugin / theme home directory.
#
# OPTIONS
# <name> Name of the package or theme.
function omf.packages.cd -a name -d "Change the current working directory to plugin / theme home directory."
if test -z "$name"
pushd $OMF_PATH
return 0
end
for path in {$OMF_CONFIG,$OMF_PATH}/{pkg,themes}/$name
if test -e "$path"
pushd $path
return 0
end
end
echo (omf::err)"$name is not a valid package/theme name"(omf::off) 1^&2
return $OMF_INVALID_ARG
end

View File

@ -55,9 +55,9 @@ function omf -d "Oh My Fish"
case "c" "cd"
switch (count $argv)
case 1
omf.cd
omf.packages.cd
case 2
omf.cd $argv[2]
omf.packages.cd $argv[2]
case "*"
echo (omf::err)"Invalid number of arguments"(omf::off) 1^&2
echo "Usage: $_ "(omf::em)"$argv[1]"(omf::off)" <name>" 1^&2