From 66c232f0b15e0ea7d84bb533c7a7a775ef8572d5 Mon Sep 17 00:00:00 2001 From: Marius Melzer Date: Wed, 12 Aug 2015 14:57:25 +0200 Subject: [PATCH 1/7] Add show all available themes/plugins and download theme/plugin commands to omf --- plugins/omf/omf.fish | 8 ++++++++ plugins/omf/omf.packages.fish | 32 +++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/plugins/omf/omf.fish b/plugins/omf/omf.fish index 15b89ee..f8e60f8 100644 --- a/plugins/omf/omf.fish +++ b/plugins/omf/omf.fish @@ -19,6 +19,14 @@ function omf -d "Oh My Fish helper" if [ $status -eq 0 ] omf.log 'green' 'Oh My Fish has been successfully updated.' end + case 'available-plugins' + omf.packages --available-plugins + case 'available-themes' + omf.packages --available-themes + case 'download-plugin' + omf.packages --download-plugin $argv[2] + case 'download-theme' + omf.packages --download-theme $argv[2] case '*' omf.helper end diff --git a/plugins/omf/omf.packages.fish b/plugins/omf/omf.packages.fish index f590f03..5cc2721 100644 --- a/plugins/omf/omf.packages.fish +++ b/plugins/omf/omf.packages.fish @@ -11,12 +11,20 @@ # Update all packages # --list # List all active packages +# --available-plugins +# List all plugins available from the oh-my-fish Github repository +# --available-themes +# List all themes available from the oh-my-fish Github repository +# --download-plugin [PLUGIN] +# Download and install PLUGIN +# --download-theme [THEME] +# Download and install THEME # # DESCRIPTION # Manage all plugins and themes specified on the $fish_plugins # and $fish_theme variables # -function omf.packages --argument-names options -d 'Manage all plugins and themes' +function omf.packages --argument-names options arg -d 'Manage all plugins and themes' set -g __omf_packages_modified 0 switch $options @@ -51,11 +59,33 @@ function omf.packages --argument-names options -d 'Manage all plugins and themes if test -n "$fish_theme" omf.log normal $fish_theme end + case '--available-plugins' + get_all_repos | grep "plugin-" | cut -d "-" -f 2- | sort | paste -sd ' ' - + case '--available-themes' + get_all_repos | grep "theme-" | cut -d "-" -f 2- | sort | paste -sd ' ' - + case '--download-plugin' + omf.packages.install --plugin $arg + case '--download-theme' + omf.packages.install --theme $arg case '*' omf.log red 'Unknown option' end end +function get_all_repos + set url "https://api.github.com/orgs/oh-my-fish/repos" + set page_count (curl -sI "$url?page=1&per_page=100" | sed -nr 's/^Link:.*page=([0-9]+)&per_page=100>; rel="last".*/\1/p') + + if echo $page_count | grep -vE '^[0-9]+$' + echo "Could not access Github API" >&2 + exit 1 + end + + for i in (seq $page_count) + curl -s "$url?page=$i&per_page=100" | grep \"name\" | tr \": " " | awk '{print $2}' + end +end + function omf.packages.report.installing -e omf_package_installing omf.log -n white "Installing $argv... " end From 6d9bb3c2dbb6adc3f1f2d9f9b19b1dc6600491ea Mon Sep 17 00:00:00 2001 From: Marius Melzer Date: Wed, 12 Aug 2015 14:59:58 +0200 Subject: [PATCH 2/7] add command explanations to omf.helper --- plugins/omf/omf.helper.fish | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugins/omf/omf.helper.fish b/plugins/omf/omf.helper.fish index ccfbf68..9236788 100644 --- a/plugins/omf/omf.helper.fish +++ b/plugins/omf/omf.helper.fish @@ -13,5 +13,9 @@ function omf.helper -d 'Prints all functions supported by Oh My Fish helper' omf.log normal ' omf update' omf.log normal ' omf list' omf.log normal ' omf self-update' + omf.log normal ' omf available-plugins' + omf.log normal ' omf available-themes' + omf.log normal ' omf download-plugin' + omf.log normal ' omf download-theme' end From 0072934733fc717d5b4ba56e53390cd5584222c1 Mon Sep 17 00:00:00 2001 From: Marius Melzer Date: Wed, 12 Aug 2015 18:06:42 +0200 Subject: [PATCH 3/7] change cli and create omf.remote from get_all_repos --- plugins/omf/omf.fish | 18 +++++------ plugins/omf/omf.helper.fish | 5 +-- plugins/omf/omf.packages.fish | 57 ++++++++++++++--------------------- plugins/omf/omf.remote.fish | 39 ++++++++++++++++++++++++ 4 files changed, 71 insertions(+), 48 deletions(-) create mode 100644 plugins/omf/omf.remote.fish diff --git a/plugins/omf/omf.fish b/plugins/omf/omf.fish index f8e60f8..d72c73c 100644 --- a/plugins/omf/omf.fish +++ b/plugins/omf/omf.fish @@ -8,7 +8,11 @@ function omf -d "Oh My Fish helper" if test (count $argv) -gt 0 switch $argv[1] case 'install' - omf.packages --install + if test (count $argv) -gt 2 + omf.packages --install $argv[2] $argv[3] + else + omf.packages --install + end case 'update' omf.packages --update case 'list' 'ls' @@ -19,14 +23,10 @@ function omf -d "Oh My Fish helper" if [ $status -eq 0 ] omf.log 'green' 'Oh My Fish has been successfully updated.' end - case 'available-plugins' - omf.packages --available-plugins - case 'available-themes' - omf.packages --available-themes - case 'download-plugin' - omf.packages --download-plugin $argv[2] - case 'download-theme' - omf.packages --download-theme $argv[2] + case 'plugins' + omf.packages --plugins + case 'themes' + omf.packages --themes case '*' omf.helper end diff --git a/plugins/omf/omf.helper.fish b/plugins/omf/omf.helper.fish index 9236788..ee19fe5 100644 --- a/plugins/omf/omf.helper.fish +++ b/plugins/omf/omf.helper.fish @@ -10,12 +10,9 @@ function omf.helper -d 'Prints all functions supported by Oh My Fish helper' omf.log normal '' omf.log normal ' Examples:' omf.log normal ' omf install' + omf.log normal ' omf install --plugin|--theme NAME' omf.log normal ' omf update' omf.log normal ' omf list' omf.log normal ' omf self-update' - omf.log normal ' omf available-plugins' - omf.log normal ' omf available-themes' - omf.log normal ' omf download-plugin' - omf.log normal ' omf download-theme' end diff --git a/plugins/omf/omf.packages.fish b/plugins/omf/omf.packages.fish index 5cc2721..b343220 100644 --- a/plugins/omf/omf.packages.fish +++ b/plugins/omf/omf.packages.fish @@ -7,36 +7,41 @@ # OPTIONS # --install # Install all packages +# --install --plugin|--theme NAME +# Install one theme/plugin # --update # Update all packages # --list # List all active packages -# --available-plugins +# --plugins # List all plugins available from the oh-my-fish Github repository -# --available-themes +# --themes # List all themes available from the oh-my-fish Github repository -# --download-plugin [PLUGIN] -# Download and install PLUGIN -# --download-theme [THEME] -# Download and install THEME # # DESCRIPTION # Manage all plugins and themes specified on the $fish_plugins # and $fish_theme variables # -function omf.packages --argument-names options arg -d 'Manage all plugins and themes' +function omf.packages --argument-names options arg1 arg2 -d 'Manage all plugins and themes' set -g __omf_packages_modified 0 switch $options case '--install' - for plugin in $fish_plugins - omf.packages.install --plugin $plugin - end + switch "$arg1" + case '--plugin' + omf.packages.install --plugin $arg2 + case '--theme' + omf.packages.install --theme $arg2 + case "" + for plugin in $fish_plugins + omf.packages.install --plugin $plugin + end - omf.packages.install --theme $fish_theme + omf.packages.install --theme $fish_theme - if [ $__omf_packages_modified -eq 0 ] - omf.log green 'All packages were already installed.' + if [ $__omf_packages_modified -eq 0 ] + omf.log green 'All packages were already installed.' + end end case '--update' for plugin in $fish_plugins @@ -59,33 +64,15 @@ function omf.packages --argument-names options arg -d 'Manage all plugins and th if test -n "$fish_theme" omf.log normal $fish_theme end - case '--available-plugins' - get_all_repos | grep "plugin-" | cut -d "-" -f 2- | sort | paste -sd ' ' - - case '--available-themes' - get_all_repos | grep "theme-" | cut -d "-" -f 2- | sort | paste -sd ' ' - - case '--download-plugin' - omf.packages.install --plugin $arg - case '--download-theme' - omf.packages.install --theme $arg + case '--plugins' + omf.remote --plugins | paste -sd ' ' - + case '--themes' + omf.remote --themes | paste -sd ' ' - case '*' omf.log red 'Unknown option' end end -function get_all_repos - set url "https://api.github.com/orgs/oh-my-fish/repos" - set page_count (curl -sI "$url?page=1&per_page=100" | sed -nr 's/^Link:.*page=([0-9]+)&per_page=100>; rel="last".*/\1/p') - - if echo $page_count | grep -vE '^[0-9]+$' - echo "Could not access Github API" >&2 - exit 1 - end - - for i in (seq $page_count) - curl -s "$url?page=$i&per_page=100" | grep \"name\" | tr \": " " | awk '{print $2}' - end -end - function omf.packages.report.installing -e omf_package_installing omf.log -n white "Installing $argv... " end diff --git a/plugins/omf/omf.remote.fish b/plugins/omf/omf.remote.fish new file mode 100644 index 0000000..e3d441c --- /dev/null +++ b/plugins/omf/omf.remote.fish @@ -0,0 +1,39 @@ +# NAME +# omf.remote - List remote plugins and themes +# +# SYNOPSIS +# omf.remote [OPTIONS] +# +# OPTIONS +# --plugins +# List all available plugins +# --themes +# List all available themes +# +# DESCRIPTION +# List remote plugins and themes from the oh-my-fish Github repository +# +function omf.remote --argument-names options -d 'List remote plugins and themes' + set url "https://api.github.com/orgs/oh-my-fish/repos" + set page_count (curl -sI "$url?page=1&per_page=100" | sed -nr 's/^Link:.*page=([0-9]+)&per_page=100>; rel="last".*/\1/p') + + if echo $page_count | grep -vE '^[0-9]+$' + echo "Could not access Github API" >&2 + exit 1 + end + + set repos "" + for i in (seq $page_count) + set answer (curl -s "$url?page=$i&per_page=100" | grep \"name\" | tr \": " " | awk '{print $2}') + set repos "$answer $repos" + end + + switch $options + case '--plugins' + echo $repos | tr ' ' "\\n" | grep "plugin-" | cut -d "-" -f 2- | sort | paste -sd " " - + case '--themes' + echo $repos | tr ' ' "\\n" | grep "theme-" | cut -d "-" -f 2- | sort | paste -sd " " - + case '*' + omf.log red 'Unknown option' + end +end From ccc8fd69f7a23ea28948b460f1f7a62cb698c4cc Mon Sep 17 00:00:00 2001 From: Marius Melzer Date: Wed, 12 Aug 2015 18:41:50 +0200 Subject: [PATCH 4/7] remove duplicated paste -sd ' ' - --- plugins/omf/omf.packages.fish | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/omf/omf.packages.fish b/plugins/omf/omf.packages.fish index b343220..192d038 100644 --- a/plugins/omf/omf.packages.fish +++ b/plugins/omf/omf.packages.fish @@ -65,9 +65,9 @@ function omf.packages --argument-names options arg1 arg2 -d 'Manage all plugins omf.log normal $fish_theme end case '--plugins' - omf.remote --plugins | paste -sd ' ' - + omf.remote --plugins case '--themes' - omf.remote --themes | paste -sd ' ' - + omf.remote --themes case '*' omf.log red 'Unknown option' end From df3d9794ed8969f80d07bb0c1b0e853f2cbfdb9c Mon Sep 17 00:00:00 2001 From: Marius Melzer Date: Wed, 12 Aug 2015 19:26:10 +0200 Subject: [PATCH 5/7] add plugins/themes options to omf.helper --- plugins/omf/omf.helper.fish | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/omf/omf.helper.fish b/plugins/omf/omf.helper.fish index ee19fe5..f79bf0b 100644 --- a/plugins/omf/omf.helper.fish +++ b/plugins/omf/omf.helper.fish @@ -14,5 +14,7 @@ function omf.helper -d 'Prints all functions supported by Oh My Fish helper' omf.log normal ' omf update' omf.log normal ' omf list' omf.log normal ' omf self-update' + omf.log normal ' omf plugins' + omf.log normal ' omf themes' end From 6a3c257511fb5dc9c6194e68399e8ae753fa5358 Mon Sep 17 00:00:00 2001 From: Marius Melzer Date: Thu, 13 Aug 2015 10:21:49 +0200 Subject: [PATCH 6/7] replace sed command in omf.remote to work on mac osx too --- plugins/omf/omf.remote.fish | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/omf/omf.remote.fish b/plugins/omf/omf.remote.fish index e3d441c..c660ca8 100644 --- a/plugins/omf/omf.remote.fish +++ b/plugins/omf/omf.remote.fish @@ -15,7 +15,7 @@ # function omf.remote --argument-names options -d 'List remote plugins and themes' set url "https://api.github.com/orgs/oh-my-fish/repos" - set page_count (curl -sI "$url?page=1&per_page=100" | sed -nr 's/^Link:.*page=([0-9]+)&per_page=100>; rel="last".*/\1/p') + set page_count (curl -sI "$url?page=1&per_page=100" | grep "^Link" | sed 's/Link:.*page=\([0-9]*\)&per_page=100>; rel="last".*/\1/') if echo $page_count | grep -vE '^[0-9]+$' echo "Could not access Github API" >&2 From 080345981b4c7f4362af75220a48737e6f4a41df Mon Sep 17 00:00:00 2001 From: Marius Melzer Date: Thu, 13 Aug 2015 10:25:36 +0200 Subject: [PATCH 7/7] remove installing a concrete plugin/theme from main cli of omf --- plugins/omf/omf.fish | 6 +----- plugins/omf/omf.helper.fish | 2 -- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/plugins/omf/omf.fish b/plugins/omf/omf.fish index d72c73c..3db2815 100644 --- a/plugins/omf/omf.fish +++ b/plugins/omf/omf.fish @@ -8,11 +8,7 @@ function omf -d "Oh My Fish helper" if test (count $argv) -gt 0 switch $argv[1] case 'install' - if test (count $argv) -gt 2 - omf.packages --install $argv[2] $argv[3] - else - omf.packages --install - end + omf.packages --install case 'update' omf.packages --update case 'list' 'ls' diff --git a/plugins/omf/omf.helper.fish b/plugins/omf/omf.helper.fish index f79bf0b..fe979e4 100644 --- a/plugins/omf/omf.helper.fish +++ b/plugins/omf/omf.helper.fish @@ -10,11 +10,9 @@ function omf.helper -d 'Prints all functions supported by Oh My Fish helper' omf.log normal '' omf.log normal ' Examples:' omf.log normal ' omf install' - omf.log normal ' omf install --plugin|--theme NAME' omf.log normal ' omf update' omf.log normal ' omf list' omf.log normal ' omf self-update' omf.log normal ' omf plugins' omf.log normal ' omf themes' end -