From c232f1019c3792756668bf6e2410bbd69e24a1f5 Mon Sep 17 00:00:00 2001 From: Bruno Pinto Date: Sun, 31 May 2015 14:49:40 +0100 Subject: [PATCH] Closes #381: oh-my-fish self update --- plugins/omf/omf.fish | 6 ++++++ plugins/omf/omf.git.fish | 14 ++++++++++++++ plugins/omf/omf.helper.fish | 1 + plugins/omf/omf.packages.fish | 1 + plugins/omf/omf.packages.install.fish | 4 ++-- plugins/omf/omf.packages.update.fish | 8 ++++---- 6 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 plugins/omf/omf.git.fish diff --git a/plugins/omf/omf.fish b/plugins/omf/omf.fish index a595417..15b89ee 100644 --- a/plugins/omf/omf.fish +++ b/plugins/omf/omf.fish @@ -13,6 +13,12 @@ function omf -d "Oh My Fish helper" omf.packages --update case 'list' 'ls' omf.packages --list + case 'self-update' + omf.git --update $fish_path + + if [ $status -eq 0 ] + omf.log 'green' 'Oh My Fish has been successfully updated.' + end case '*' omf.helper end diff --git a/plugins/omf/omf.git.fish b/plugins/omf/omf.git.fish new file mode 100644 index 0000000..bf9825d --- /dev/null +++ b/plugins/omf/omf.git.fish @@ -0,0 +1,14 @@ +function omf.git + switch $argv[1] + case '--clone' + set -l repo_url $argv[2] + set -l path $argv[3] + + git clone --quiet $repo_url $path ^ /tmp/oh-my-fish.clone.log + case '--update' + set -l path $argv[2] + return (cd $path; and git pull --rebase > /dev/null; echo $status) + case '*' + omf.log red 'Unknown option' + end +end diff --git a/plugins/omf/omf.helper.fish b/plugins/omf/omf.helper.fish index 5a6ccc5..ccfbf68 100644 --- a/plugins/omf/omf.helper.fish +++ b/plugins/omf/omf.helper.fish @@ -12,5 +12,6 @@ function omf.helper -d 'Prints all functions supported by Oh My Fish helper' omf.log normal ' omf install' omf.log normal ' omf update' omf.log normal ' omf list' + omf.log normal ' omf self-update' end diff --git a/plugins/omf/omf.packages.fish b/plugins/omf/omf.packages.fish index 97e850b..dc1612d 100644 --- a/plugins/omf/omf.packages.fish +++ b/plugins/omf/omf.packages.fish @@ -65,6 +65,7 @@ function omf.packages.report.failed -e omf_package_install_failed -e omf_package set_color yellow cat /tmp/oh-my-fish.clone.log + echo -e '' set_color normal set __omf_packages_modified (expr $__omf_packages_modified + 1) diff --git a/plugins/omf/omf.packages.install.fish b/plugins/omf/omf.packages.install.fish index 51e90b7..8285a32 100644 --- a/plugins/omf/omf.packages.install.fish +++ b/plugins/omf/omf.packages.install.fish @@ -15,7 +15,7 @@ function omf.packages.install --argument-names type name -d "Install a plugin or # Plugin is already installed. Skipping. else emit omf_package_installing $name - git clone --quiet "https://github.com/oh-my-fish/plugin-$name" $fish_path/plugins/$name ^ /tmp/oh-my-fish.clone.log + omf.git --clone "https://github.com/oh-my-fish/plugin-$name" $fish_path/plugins/$name if [ $status -eq 0 ] emit omf_package_installed $name @@ -28,7 +28,7 @@ function omf.packages.install --argument-names type name -d "Install a plugin or # Theme is already installed. Skipping. else emit omf_package_installing $name - git clone --quiet "https://github.com/oh-my-fish/theme-$name" $fish_path/themes/$name ^ /tmp/oh-my-fish.clone.log + omf.git --clone "https://github.com/oh-my-fish/plugin-$name" $fish_path/themes/$name if [ $status -eq 0 ] emit omf_package_installed $name diff --git a/plugins/omf/omf.packages.update.fish b/plugins/omf/omf.packages.update.fish index 3813e74..f9016ba 100644 --- a/plugins/omf/omf.packages.update.fish +++ b/plugins/omf/omf.packages.update.fish @@ -15,12 +15,12 @@ function omf.packages.update --argument-names type name -d "Update a plugin or t case '--plugin' if [ -e $fish_path/plugins/$name -a -e $fish_path/plugins/$name/.git ] emit omf_package_updating $name - echo (cd $fish_path/plugins/$name; and git pull --rebase > /dev/null) >/dev/null + omf.git --update $fish_path/plugins/$name emit omf_package_updated $name else if [ -e $fish_custom/plugins/$name -a -e $fish_custom/plugins/$name/.git ] emit omf_package_updating $name - echo (cd $fish_custom/plugins/$name; and git pull --rebase > /dev/null) >/dev/null + omf.git --update $fish_path/plugins/$name emit omf_package_updated $name else # Plugin is not installed or not a git repo. Skipping. @@ -29,12 +29,12 @@ function omf.packages.update --argument-names type name -d "Update a plugin or t case '--theme' if [ -e $fish_path/themes/$name -a -e $fish_path/themes/$name/.git ] emit omf_package_updating $name - echo (cd $fish_path/themes/$name; and git pull --rebase > /dev/null) >/dev/null + omf.git --update $fish_path/themes/$name emit omf_package_updated $name else if [ -e $fish_custom/themes/$name -a -e $fish_custom/themes/$name/.git ] emit omf_package_updating $name - echo (cd $fish_custom/themes/$name; and git pull --rebase > /dev/null) >/dev/null + omf.git --update $fish_custom/themes/$name emit omf_package_updated $name else # Theme is not installed or not a git repo. Skipping.