From 7025525ef13f6675c452349822bc4278caa28a8c Mon Sep 17 00:00:00 2001 From: Bruno Pinto Date: Tue, 6 Oct 2015 20:50:34 +0100 Subject: [PATCH] Simplify `omf cd` code This also namespace the function to `omf.packages`. --- pkg/omf/cli/omf.cd.fish | 25 ------------------------- pkg/omf/cli/omf.packages.cd.fish | 22 ++++++++++++++++++++++ pkg/omf/omf.fish | 4 ++-- 3 files changed, 24 insertions(+), 27 deletions(-) delete mode 100644 pkg/omf/cli/omf.cd.fish create mode 100644 pkg/omf/cli/omf.packages.cd.fish diff --git a/pkg/omf/cli/omf.cd.fish b/pkg/omf/cli/omf.cd.fish deleted file mode 100644 index d7f98f5..0000000 --- a/pkg/omf/cli/omf.cd.fish +++ /dev/null @@ -1,25 +0,0 @@ -# SYNOPSIS -# Change the current working directory to plugin / theme home directory. -# -# OPTIONS -# 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 diff --git a/pkg/omf/cli/omf.packages.cd.fish b/pkg/omf/cli/omf.packages.cd.fish new file mode 100644 index 0000000..e412f39 --- /dev/null +++ b/pkg/omf/cli/omf.packages.cd.fish @@ -0,0 +1,22 @@ +# SYNOPSIS +# Change the current working directory to plugin / theme home directory. +# +# OPTIONS +# 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 diff --git a/pkg/omf/omf.fish b/pkg/omf/omf.fish index 837c195..5c3bd98 100644 --- a/pkg/omf/omf.fish +++ b/pkg/omf/omf.fish @@ -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)" " 1^&2