diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 31fbf99..953d174 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -59,7 +59,7 @@ The following syntax is more concise, but arguably less transparent. > You still may use `and` / `or` statements if you consider `if..else..then` to be overkill. ```fish -set -q VAR; set -g VAR 42 +set -q VAR; or set -g VAR 42 ``` ### Functions @@ -80,16 +80,9 @@ function greet -a message -d "Display a greeting message" end ``` -`fish` does not have private functions, so in order to avoid polluting the global namespace, use a prefix based in the scope of your code. For example, if you are writing a `ninja` plugin using `__ninja_function_name`. +In order to avoid name collision, name your functions using a prefix based on the name of your package. For example, if you are writing a `ninja` package use `ninja.function_name`. -If you are writing a function inside another function, prefix the inner one with the parent's name. - -```fish -function parent - function parent_child - end -end -``` +`fish` does not have private functions, so in order to avoid polluting the global namespace, use double underscore before your function name. For example, if you are writing a `ninja` plugin using `__ninja.function_name`. Note that it's still possible to mimic private functions in `fish` by deleting the function before returning using `functions -e function_name` diff --git a/pkg/omf/cli/omf_destroy.fish b/pkg/omf/cli/omf.destroy.fish similarity index 69% rename from pkg/omf/cli/omf_destroy.fish rename to pkg/omf/cli/omf.destroy.fish index f33f207..1e7a6f7 100644 --- a/pkg/omf/cli/omf_destroy.fish +++ b/pkg/omf/cli/omf.destroy.fish @@ -1,7 +1,7 @@ -function omf_destroy -d "Remove Oh My Fish" +function omf.destroy -d "Remove Oh My Fish" echo (omf::dim)"Removing Oh My Fish..."(omf::off) - omf_remove_package (basename $OMF_PATH/pkg/*) >/dev/null ^&1 + omf.remove_package (basename $OMF_PATH/pkg/*) >/dev/null ^&1 if test -e "$HOME/.config/fish/config.copy" mv "$HOME/.config/fish/config".{copy,fish} diff --git a/pkg/omf/cli/omf_help.fish b/pkg/omf/cli/omf.help.fish similarity index 97% rename from pkg/omf/cli/omf_help.fish rename to pkg/omf/cli/omf.help.fish index e396fd6..8b01eaa 100644 --- a/pkg/omf/cli/omf_help.fish +++ b/pkg/omf/cli/omf.help.fish @@ -1,4 +1,4 @@ -function omf_help +function omf.help echo \n"\ "(omf::dim)"Usage"(omf::off)" omf "(omf::em)"action"(omf::off)" [options] diff --git a/pkg/omf/cli/omf_install_package.fish b/pkg/omf/cli/omf.install_package.fish similarity index 93% rename from pkg/omf/cli/omf_install_package.fish rename to pkg/omf/cli/omf.install_package.fish index 0e76e10..fb4c323 100644 --- a/pkg/omf/cli/omf_install_package.fish +++ b/pkg/omf/cli/omf.install_package.fish @@ -1,4 +1,4 @@ -function omf_install_package +function omf.install_package for search in $argv if test -e $OMF_PATH/db/pkg/$search set target pkg/$search @@ -20,7 +20,7 @@ function omf_install_package if test -e $OMF_PATH/$target echo (omf::dim)"Updating $search..."(omf::off) pushd $OMF_PATH/$target - omf_util_sync "origin" >/dev/null ^&1 + omf.util_sync "origin" >/dev/null ^&1 popd echo (omf::em)"✔ $search up to date."(omf::off) else diff --git a/pkg/omf/cli/omf_list_db_packages.fish b/pkg/omf/cli/omf.list_db_packages.fish similarity index 86% rename from pkg/omf/cli/omf_list_db_packages.fish rename to pkg/omf/cli/omf.list_db_packages.fish index d4c8aba..a1559e4 100644 --- a/pkg/omf/cli/omf_list_db_packages.fish +++ b/pkg/omf/cli/omf.list_db_packages.fish @@ -1,5 +1,5 @@ # List all packages available to install from the registry. -function omf_list_db_packages +function omf.list_db_packages for item in (basename $OMF_PATH/db/pkg/*) contains $item (basename {$OMF_PATH,$OMF_CONFIG}/pkg/*); or echo $item end diff --git a/pkg/omf/cli/omf_list_installed_packages.fish b/pkg/omf/cli/omf.list_installed_packages.fish similarity index 78% rename from pkg/omf/cli/omf_list_installed_packages.fish rename to pkg/omf/cli/omf.list_installed_packages.fish index 4ac9e6d..05649cb 100644 --- a/pkg/omf/cli/omf_list_installed_packages.fish +++ b/pkg/omf/cli/omf.list_installed_packages.fish @@ -1,5 +1,5 @@ # List all packages installed from the registry. -function omf_list_installed_packages +function omf.list_installed_packages for item in (basename $OMF_PATH/pkg/*) test $item = omf; or echo $item end diff --git a/pkg/omf/cli/omf.list_installed_themes.fish b/pkg/omf/cli/omf.list_installed_themes.fish new file mode 100644 index 0000000..1886382 --- /dev/null +++ b/pkg/omf/cli/omf.list_installed_themes.fish @@ -0,0 +1,3 @@ +function omf.list_installed_themes + basename $OMF_PATH/themes/* +end diff --git a/pkg/omf/cli/omf_list_local_packages.fish b/pkg/omf/cli/omf.list_local_packages.fish similarity index 83% rename from pkg/omf/cli/omf_list_local_packages.fish rename to pkg/omf/cli/omf.list_local_packages.fish index 6d4c6b7..b79ec54 100644 --- a/pkg/omf/cli/omf_list_local_packages.fish +++ b/pkg/omf/cli/omf.list_local_packages.fish @@ -1,5 +1,5 @@ # List all custom packages and packages installed from the registry. -function omf_list_local_packages +function omf.list_local_packages for item in (basename {$OMF_PATH,$OMF_CONFIG}/pkg/*) test $item = omf; or echo $item end diff --git a/pkg/omf/cli/omf_list_themes.fish b/pkg/omf/cli/omf.list_themes.fish similarity index 89% rename from pkg/omf/cli/omf_list_themes.fish rename to pkg/omf/cli/omf.list_themes.fish index 3294bf0..26c0413 100644 --- a/pkg/omf/cli/omf_list_themes.fish +++ b/pkg/omf/cli/omf.list_themes.fish @@ -1,4 +1,4 @@ -function omf_list_themes +function omf.list_themes set -l seen "" for theme in (basename $OMF_PATH/db/themes/*) \ (basename {$OMF_PATH,$OMF_CONFIG}/themes/*) diff --git a/pkg/omf/cli/omf_new.fish b/pkg/omf/cli/omf.new.fish similarity index 80% rename from pkg/omf/cli/omf_new.fish rename to pkg/omf/cli/omf.new.fish index 5f90e5e..b0f303e 100644 --- a/pkg/omf/cli/omf_new.fish +++ b/pkg/omf/cli/omf.new.fish @@ -1,4 +1,4 @@ -function omf_new -a option name +function omf.new -a option name switch $option case "p" "pkg" "pack" "packg" "package" set option "pkg" @@ -9,12 +9,12 @@ function omf_new -a option name return $OMF_INVALID_ARG end - if not omf_util_valid_package "$name" + if not omf.util_valid_package "$name" echo (omf::err)"$name is not a valid package/theme name"(omf::off) 1^&2 return $OMF_INVALID_ARG end - if set -l dir (omf_util_mkdir "$option/$name") + if set -l dir (omf.util_mkdir "$option/$name") cd $dir set -l github (git config github.user) @@ -23,7 +23,7 @@ function omf_new -a option name set -l user (git config user.name) test -z "$user"; and set user "{{USER}}" - omf_new_from_template "$OMF_PATH/pkg/omf/templates/$option" \ + omf.new_from_template "$OMF_PATH/pkg/omf/templates/$option" \ $github $user $name echo (omf::em)"Switched to $dir"(omf::off) diff --git a/pkg/omf/cli/omf_new_from_template.fish b/pkg/omf/cli/omf.new_from_template.fish similarity index 84% rename from pkg/omf/cli/omf_new_from_template.fish rename to pkg/omf/cli/omf.new_from_template.fish index 33f1312..77a9204 100644 --- a/pkg/omf/cli/omf_new_from_template.fish +++ b/pkg/omf/cli/omf.new_from_template.fish @@ -1,9 +1,9 @@ -function omf_new_from_template -a path github user name +function omf.new_from_template -a path github user name for file in $path/* if test -d $file mkdir (basename $file) pushd (basename $file) - omf_new_from_template $file $github $user $name + omf.new_from_template $file $github $user $name else set -l target (begin if test (basename $file) = "{{NAME}}.fish" diff --git a/pkg/omf/cli/omf_query_env.fish b/pkg/omf/cli/omf.query_env.fish similarity index 66% rename from pkg/omf/cli/omf_query_env.fish rename to pkg/omf/cli/omf.query_env.fish index 25bdc56..a4f165a 100644 --- a/pkg/omf/cli/omf_query_env.fish +++ b/pkg/omf/cli/omf.query_env.fish @@ -1,17 +1,18 @@ -function omf_query_env - function __omf_print_pretty_path -a path +function omf.query_env + function __omf.print_pretty_path -a path printf "%s\n" $path \ | sed "s|$HOME|"(omf::em)"~"(omf::off)"|g" \ | sed "s|/|"(omf::em)"/"(omf::off)"|g" end + if not set -q argv[1] for var in (set) echo (omf::dim)(echo $var | awk '{ printf $1"\n"; }')(omf::off) - echo (omf::em)(__omf_print_pretty_path (echo $var | awk '{$1=""; print $0}'))(omf::off) + echo (omf::em)(__omf.print_pretty_path (echo $var | awk '{$1=""; print $0}'))(omf::off) end else for key in $$argv[1] - __omf_print_pretty_path $key + __omf.print_pretty_path $key end end end diff --git a/pkg/omf/cli/omf_remove_package.fish b/pkg/omf/cli/omf.remove_package.fish similarity index 91% rename from pkg/omf/cli/omf_remove_package.fish rename to pkg/omf/cli/omf.remove_package.fish index a572df1..412087b 100644 --- a/pkg/omf/cli/omf_remove_package.fish +++ b/pkg/omf/cli/omf.remove_package.fish @@ -1,6 +1,6 @@ -function omf_remove_package +function omf.remove_package for pkg in $argv - if not omf_util_valid_package $pkg + if not omf.util_valid_package $pkg if test $pkg = "omf" echo (omf::err)"You can't remove `omf`"(omf::off) 1^&2 else diff --git a/pkg/omf/cli/omf_submit.fish b/pkg/omf/cli/omf.submit.fish similarity index 92% rename from pkg/omf/cli/omf_submit.fish rename to pkg/omf/cli/omf.submit.fish index 9bea20f..2dad408 100644 --- a/pkg/omf/cli/omf_submit.fish +++ b/pkg/omf/cli/omf.submit.fish @@ -5,7 +5,7 @@ # name Name of the package. # [url] URL to the package repository. -function omf_submit -a name url -d "Submit a package to the registry" +function omf.submit -a name url -d "Submit a package to the registry" switch (dirname $name) case pkg case themes @@ -15,7 +15,7 @@ function omf_submit -a name url -d "Submit a package to the registry" end set -l pkg (basename $name) - if not omf_util_valid_package $pkg + if not omf.util_valid_package $pkg echo (omf::err)"$pkg is not a valid package/theme name"(omf::off) 1^&2 return $OMF_INVALID_ARG end diff --git a/pkg/omf/cli/omf_theme.fish b/pkg/omf/cli/omf.theme.fish similarity index 96% rename from pkg/omf/cli/omf_theme.fish rename to pkg/omf/cli/omf.theme.fish index 14d845a..594e2d9 100644 --- a/pkg/omf/cli/omf_theme.fish +++ b/pkg/omf/cli/omf.theme.fish @@ -1,4 +1,4 @@ -function omf_theme +function omf.theme if not test -e $OMF_CONFIG/themes/$argv[1] if not test -e $OMF_PATH/themes/$argv[1] set -l theme $OMF_PATH/db/themes/$argv[1] diff --git a/pkg/omf/cli/omf_update.fish b/pkg/omf/cli/omf.update.fish similarity index 86% rename from pkg/omf/cli/omf_update.fish rename to pkg/omf/cli/omf.update.fish index 153e97c..105a5c3 100644 --- a/pkg/omf/cli/omf_update.fish +++ b/pkg/omf/cli/omf.update.fish @@ -1,4 +1,4 @@ -function omf_update +function omf.update set -l repo "upstream" test -z (git config --get remote.upstream.url) and set -l repo "origin" @@ -10,7 +10,7 @@ function omf_update if git pull --rebase $repo master >/dev/null ^&1 git stash apply >/dev/null ^&1 else - omf_util_sync "origin" + omf.util_sync "origin" end end -end \ No newline at end of file +end diff --git a/pkg/omf/cli/omf_version.fish b/pkg/omf/cli/omf.version.fish similarity index 64% rename from pkg/omf/cli/omf_version.fish rename to pkg/omf/cli/omf.version.fish index e4c0623..53e54c7 100644 --- a/pkg/omf/cli/omf_version.fish +++ b/pkg/omf/cli/omf.version.fish @@ -1,3 +1,3 @@ -function omf_version +function omf.version echo "Oh My Fish! $OMF_VERSION" end diff --git a/pkg/omf/cli/omf_list_installed_themes.fish b/pkg/omf/cli/omf_list_installed_themes.fish deleted file mode 100644 index 8c07ac8..0000000 --- a/pkg/omf/cli/omf_list_installed_themes.fish +++ /dev/null @@ -1,3 +0,0 @@ -function omf_list_installed_themes - basename $OMF_PATH/themes/* -end diff --git a/pkg/omf/completions/omf.fish b/pkg/omf/completions/omf.fish index e3357a0..39c6c8b 100644 --- a/pkg/omf/completions/omf.fish +++ b/pkg/omf/completions/omf.fish @@ -1,30 +1,30 @@ # SYNOPSIS # Completions for Oh My Fish CLI -function __omf_is_single_opt +function __omf.is_single_opt test (count (commandline -opc)) -le 1 end -function __omf_opt_is +function __omf.opt_is set -l cmd (commandline -opc) test (count $cmd) -gt 1; and contains -- $cmd[2] $argv end complete --no-files -c omf -d "Oh My Fish" -complete -c omf -n "__omf_opt_is q query" -a (printf "%s " (set | awk '{ printf $1"\n"; }')) -complete -c omf -n "__omf_opt_is r rm remove" -a (printf "%s " (omf_list_local_packages) (omf_list_installed_themes)) -complete -c omf -n "__omf_opt_is i install" -a (printf "%s " (omf_list_db_packages)) -complete -c omf -n "__omf_opt_is t theme" -a (printf "%s " (omf_list_themes)) +complete -c omf -n "__omf.opt_is q query" -a (printf "%s " (set | awk '{ printf $1"\n"; }')) +complete -c omf -n "__omf.opt_is r rm remove" -a (printf "%s " (omf.list_local_packages) (omf.list_installed_themes)) +complete -c omf -n "__omf.opt_is i install" -a (printf "%s " (omf.list_db_packages)) +complete -c omf -n "__omf.opt_is t theme" -a (printf "%s " (omf.list_themes)) -complete -c omf -a list -n "__omf_is_single_opt" -d "List local packages" -complete -c omf -a install -n "__omf_is_single_opt" -d "Install one or more packages" -complete -c omf -a theme -n "__omf_is_single_opt" -d "List / Use themes" -complete -c omf -a remove -n "__omf_is_single_opt" -d "Remove a theme or package" -complete -c omf -a update -n "__omf_is_single_opt" -d "Update Oh My Fish" -complete -c omf -a new -n "__omf_is_single_opt" -d "Create a new package from a template" -complete -c omf -a submit -n "__omf_is_single_opt" -d "Submit a package to the registry" -complete -c omf -a query -n "__omf_is_single_opt" -d "Query environment variables" -complete -c omf -a help -n "__omf_is_single_opt" -d "Display this help" -complete -c omf -a version -n "__omf_is_single_opt" -d "Display version" -complete -c omf -a destroy -n "__omf_is_single_opt" -d "Remove Oh My Fish" +complete -c omf -a list -n "__omf.is_single_opt" -d "List local packages" +complete -c omf -a install -n "__omf.is_single_opt" -d "Install one or more packages" +complete -c omf -a theme -n "__omf.is_single_opt" -d "List / Use themes" +complete -c omf -a remove -n "__omf.is_single_opt" -d "Remove a theme or package" +complete -c omf -a update -n "__omf.is_single_opt" -d "Update Oh My Fish" +complete -c omf -a new -n "__omf.is_single_opt" -d "Create a new package from a template" +complete -c omf -a submit -n "__omf.is_single_opt" -d "Submit a package to the registry" +complete -c omf -a query -n "__omf.is_single_opt" -d "Query environment variables" +complete -c omf -a help -n "__omf.is_single_opt" -d "Display this help" +complete -c omf -a version -n "__omf.is_single_opt" -d "Display version" +complete -c omf -a destroy -n "__omf.is_single_opt" -d "Remove Oh My Fish" diff --git a/pkg/omf/omf.fish b/pkg/omf/omf.fish index b748ac0..5bab0eb 100644 --- a/pkg/omf/omf.fish +++ b/pkg/omf/omf.fish @@ -27,19 +27,19 @@ end function omf -d "Oh My Fish" if test (count $argv) -eq 0 - omf_help; and return 0 + omf.help; and return 0 end switch $argv[1] case "v" "ver" "version" - omf_version + omf.version case "q" "query" switch (count $argv) case 1 - omf_query_env + omf.query_env case 2 - omf_query_env "$argv[2]" + omf.query_env "$argv[2]" case "*" echo (omf::err)"Invalid number of arguments"(omf::off) 1^&2 echo "Usage: $_ "(omf::em)"$argv[1]"(omf::off)" []" 1^&2 @@ -47,16 +47,16 @@ function omf -d "Oh My Fish" end case "h" "help" - omf_help + omf.help case "l" "li" "lis" "lst" "list" - omf_list_local_packages | column + omf.list_local_packages | column case "i" "install" "get" if test (count $argv) -eq 1 - omf_list_db_packages | column + omf.list_db_packages | column else - omf_install_package $argv[2..-1] + omf.install_package $argv[2..-1] refresh end @@ -66,11 +66,11 @@ function omf -d "Oh My Fish" set -l regex "[[:<:]]($theme)[[:>:]]" test "$OSTYPE" != "Darwin"; and set regex "\b($theme)\b" - omf_list_themes | column | sed -E "s/$regex/"(omf::em)"\1"(omf::off)"/" + omf.list_themes | column | sed -E "s/$regex/"(omf::em)"\1"(omf::off)"/" omf::off else if test (count $argv) -eq 2 - omf_theme $argv[2] + omf.theme $argv[2] refresh else echo (omf::err)"Invalid number of arguments"(omf::off) 1^&2 @@ -84,26 +84,26 @@ function omf -d "Oh My Fish" echo "Usage: $_ "(omf::em)"$argv[1]"(omf::off)" <[package|theme] name>" 1^&2 return $OMF_INVALID_ARG end - omf_remove_package $argv[2..-1] + omf.remove_package $argv[2..-1] case "u" "up" "upd" "update" pushd $OMF_PATH echo (omf::em)"Updating Oh My Fish..."(omf::off) - if omf_update + if omf.update echo (omf::em)"Oh My Fish is up to date."(omf::off) else echo (omf::err)"Oh My Fish failed to update."(omf::off) echo "Please open a new issue here → "(omf::em)"git.io/omf-issues"(omf::off) end - omf_theme (cat $OMF_CONFIG/theme) - omf_install_package (omf_list_installed_packages) + omf.theme (cat $OMF_CONFIG/theme) + omf.install_package (omf.list_installed_packages) popd refresh case "s" "su" "sub" "submit" switch (count $argv) case 3 - omf_submit $argv[2] $argv[3] + omf.submit $argv[2] $argv[3] case "*" echo (omf::err)"Argument missing"(omf::off) 1^&2 echo "Usage: $_ "(omf::em)"$argv[1]"(omf::off)" "(omf::em)"pkg|themes"(omf::off)"/ " 1^&2 @@ -116,10 +116,10 @@ function omf -d "Oh My Fish" echo "Usage: $_ "(omf::em)"$argv[1]"(omf::off)" "(omf::em)"pkg|theme"(omf::off)" " 1^&2 return $OMF_MISSING_ARG end - omf_new $argv[2..-1] + omf.new $argv[2..-1] case "destroy" - omf_destroy + omf.destroy case "*" echo (omf::err)"$argv[1] option not recognized"(omf::off) 1^&2 diff --git a/pkg/omf/util/omf_util_fork_repo.fish b/pkg/omf/util/omf.util_fork_repo.fish similarity index 72% rename from pkg/omf/util/omf_util_fork_repo.fish rename to pkg/omf/util/omf.util_fork_repo.fish index c7b4d07..9579d8c 100644 --- a/pkg/omf/util/omf_util_fork_repo.fish +++ b/pkg/omf/util/omf.util_fork_repo.fish @@ -1,4 +1,4 @@ -function omf_util_fork_repo -a user repo +function omf.util_fork_repo -a user repo curl -u "$user" --fail --silent https://api.github.com/repos/$repo/forks \ -d "{\"user\":\"$user\"}" >/dev/null ^&1 -end \ No newline at end of file +end diff --git a/pkg/omf/util/omf_util_mkdir.fish b/pkg/omf/util/omf.util_mkdir.fish similarity index 85% rename from pkg/omf/util/omf_util_mkdir.fish rename to pkg/omf/util/omf.util_mkdir.fish index c136441..c206cad 100644 --- a/pkg/omf/util/omf_util_mkdir.fish +++ b/pkg/omf/util/omf.util_mkdir.fish @@ -1,4 +1,4 @@ -function omf_util_mkdir -a name +function omf.util_mkdir -a name set -l name "$argv[1]" if test -d "$OMF_CONFIG" set name "$OMF_CONFIG/$name" diff --git a/pkg/omf/util/omf_util_sync.fish b/pkg/omf/util/omf.util_sync.fish similarity index 78% rename from pkg/omf/util/omf_util_sync.fish rename to pkg/omf/util/omf.util_sync.fish index 5a4aa31..3eb9f20 100644 --- a/pkg/omf/util/omf_util_sync.fish +++ b/pkg/omf/util/omf.util_sync.fish @@ -1,8 +1,8 @@ -function omf_util_sync -a remote +function omf.util_sync -a remote set -l repo $remote set -q argv[1]; and set repo $argv[1] git fetch origin master git reset --hard FETCH_HEAD git clean -df -end \ No newline at end of file +end diff --git a/pkg/omf/util/omf_util_valid_package.fish b/pkg/omf/util/omf.util_valid_package.fish similarity index 89% rename from pkg/omf/util/omf_util_valid_package.fish rename to pkg/omf/util/omf.util_valid_package.fish index 2965451..c6cf8a9 100644 --- a/pkg/omf/util/omf_util_valid_package.fish +++ b/pkg/omf/util/omf.util_valid_package.fish @@ -1,4 +1,4 @@ -function omf_util_valid_package -a package +function omf.util_valid_package -a package test (echo "$package" | tr "[:upper:]" "[:lower:]") = "omf"; and return 10 switch $package case {a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}\*