From 21848fdf80e965b5eb2bf4e18172c2e6ac8b6288 Mon Sep 17 00:00:00 2001 From: Bruno Pinto Date: Tue, 26 May 2015 14:48:21 +0100 Subject: [PATCH] fish install and updated functions --- functions/Plugin.fish | 2 ++ functions/Theme.fish | 2 ++ functions/fish.fish | 20 +++++++++++ functions/fish.log.fish | 17 +++++++++ functions/fish.packages.fish | 28 +++++++++++++++ functions/fish.packages.install.fish | 36 +++++++++++++++++++ functions/fish.packages.update.fish | 53 ++++++++++++++++++++++++++++ 7 files changed, 158 insertions(+) create mode 100644 functions/fish.fish create mode 100644 functions/fish.log.fish create mode 100644 functions/fish.packages.fish create mode 100644 functions/fish.packages.install.fish create mode 100644 functions/fish.packages.update.fish diff --git a/functions/Plugin.fish b/functions/Plugin.fish index f7defd6..fcd0513 100644 --- a/functions/Plugin.fish +++ b/functions/Plugin.fish @@ -1,4 +1,6 @@ function Plugin --argument-names name + set -g fish_plugins $fish_plugins $name + if [ -e $fish_path/plugins/$name -o -e $fish_custom/plugins/$name ] import plugins/$name else diff --git a/functions/Theme.fish b/functions/Theme.fish index 4b6d929..546ea5b 100644 --- a/functions/Theme.fish +++ b/functions/Theme.fish @@ -1,4 +1,6 @@ function Theme --argument-names name + set -g fish_theme $name + if [ -e $fish_path/themes/$name -o -e $fish_custom/themes/$name ] import themes/$name else diff --git a/functions/fish.fish b/functions/fish.fish new file mode 100644 index 0000000..51791ab --- /dev/null +++ b/functions/fish.fish @@ -0,0 +1,20 @@ +# NAME +# fish - Extend default fish binary +# +# DESCRIPTION +# Extend fish binary to support plugins and themes installation +# +function fish -d "Extend fish binary" + if test (count $argv) -gt 0 + switch $argv[1] + case 'install' + fish.packages --install + case 'update' + fish.packages --update + case '*' + command fish $argv + end + else + command fish + end +end diff --git a/functions/fish.log.fish b/functions/fish.log.fish new file mode 100644 index 0000000..55eb3a8 --- /dev/null +++ b/functions/fish.log.fish @@ -0,0 +1,17 @@ +# NAME +# fish.log - simple log with color +# +# SYNOPSIS +# [...] +# +# DESCRIPTION +# Simply log a message with a specified color. +# +function fish.log -d "Simple log with color" + switch $argv[1] + case '-*' + echo $argv[1] (set_color $argv[2])$argv[3..-1](set_color normal) + case '*' + echo -e (set_color $argv[1])$argv[2..-1](set_color normal) + end +end diff --git a/functions/fish.packages.fish b/functions/fish.packages.fish new file mode 100644 index 0000000..857e438 --- /dev/null +++ b/functions/fish.packages.fish @@ -0,0 +1,28 @@ +# NAME +# fish.packages - Manage all plugins and themes +# +# SYNOPSIS +# fish.packages [OPTIONS] +# +# OPTIONS +# --install +# Install all packages +# --update +# Update all packages +# +# DESCRIPTION +# Manage all plugins and themes specified on the $fish_plugins +# and $fish_theme variables +# +function fish.packages --argument-names options -d 'Manage all plugins and themes' + set -l modified_packages 0 + + switch $options + case "--install" + fish.packages.install + case "--update" + fish.packages.update + case "*" + fish.log red 'Unknown option' + end +end diff --git a/functions/fish.packages.install.fish b/functions/fish.packages.install.fish new file mode 100644 index 0000000..57830d3 --- /dev/null +++ b/functions/fish.packages.install.fish @@ -0,0 +1,36 @@ +# NAME +# fish.packages.install - Install all plugins and themes +# +# DESCRIPTION +# Install all plugins and themes specified on the $fish_plugins +# and $fish_theme variables +# +function fish.packages.install -d "Install all plugins and themes" + set -l installed_packages 0 + + # Plugins + for plugin in $fish_plugins + if [ -e $fish_path/plugins/$plugin -o -e $fish_custom/plugins/$plugin ] + #echo "$plugin is already installed. Skipping." + else + fish.log -n white "Installing $plugin... " + git clone "https://github.com/oh-my-fish/plugins-$plugin" $fish_path/plugins/$plugin ^ /dev/null + fish.log green "√" + set -l installed_packages 1 + end + end + + # Theme + if [ -e $fish_path/themes/$fish_theme -o -e $fish_custom/themes/$fish_theme ] + #echo "$fish_theme is already installed. Skipping." + else + fish.log -n white "Installing $fish_theme... " + git clone "https://github.com/oh-my-fish/themes-$fish_theme" $fish_path/themes/$fish_theme ^ /dev/null + fish.log green "√" + set -l installed_packages 1 + end + + if [ $installed_packages -eq 0 ] + fish.log green 'All plugins were already installed.' + end +end diff --git a/functions/fish.packages.update.fish b/functions/fish.packages.update.fish new file mode 100644 index 0000000..513ce46 --- /dev/null +++ b/functions/fish.packages.update.fish @@ -0,0 +1,53 @@ +# NAME +# fish.packages.update - Update all plugins and themes +# +# DESCRIPTION +# Update all plugins and themes specified on the $fish_plugins +# and $fish_theme variables +# +function fish.packages.update -d "Update all plugins and themes" + set -l installed_packages 0 + pushd + + # Plugins + for plugin in $fish_plugins + if [ -e $fish_path/plugins/$plugin -a -e $fish_path/plugins/$plugin/.git ] + fish.log -n white "Updating $plugin... " + echo (cd $fish_path/plugins/$plugin; and git pull --rebase > /dev/null) >/dev/null + fish.log green "√" + set -l installed_packages 1 + else + if [ -e $fish_custom/plugins/$plugin -a -e $fish_custom/plugins/$plugin/.git ] + fish.log -n white "Updating $plugin... " + echo (cd $fish_custom/plugins/$plugin; and git pull --rebase > /dev/null) >/dev/null + fish.log green "√" + set -l installed_packages 1 + else + #echo "$plugin is not installed or not a git repo. Skipping." + end + end + end + + # Theme + if [ -e $fish_path/themes/$fish_theme -a -e $fish_path/themes/$fish_theme/.git ] + fish.log -n white "Updating $fish_theme... " + echo (cd $fish_path/themes/$fish_theme; and git pull --rebase > /dev/null) >/dev/null + fish.log green "√" + set -l installed_packages 1 + else + if [ -e $fish_custom/themes/$fish_theme -a -e $fish_custom/themes/$fish_theme/.git ] + fish.log -n white "Updating $fish_theme... " + echo (cd $fish_custom/themes/$fish_theme; and git pull --rebase > /dev/null) >/dev/null + fish.log green "√" + set -l installed_packages 1 + else + #echo "$fish_theme is not installed or not a git repo. Skipping." + end + end + + if [ $installed_packages -eq 0 ] + fish.log green 'No plugins to update.' + end + + popd +end