From 4190fa2e0d4f657263c45a3aec852cfda02bba5a Mon Sep 17 00:00:00 2001 From: Sasha Egorov Date: Wed, 16 Dec 2015 22:12:21 +0400 Subject: [PATCH 1/2] Meet Vagrant --- README.md | 2 ++ fish_prompt.fish | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/README.md b/README.md index 925399f..78f9124 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,7 @@ You can override some of the following default options in your `config.fish`: set -g theme_display_git no set -g theme_display_git_untracked no set -g theme_display_git_ahead_verbose yes +set -g theme_display_vagrant yes set -g theme_display_hg yes set -g theme_display_virtualenv no set -g theme_display_ruby no @@ -83,6 +84,7 @@ set -g default_user your_normal_user **Prompt options** - `theme_display_ruby`. Use `no` to completely hide all information about Ruby version. By default Ruby version displayed if there is the difference from default settings. +- `theme_display_vagrant`. This feature is disabled by default, use `yes` to display Vagrant status in your prompt. Please note, only VirtualBox provider is supported. [fish]: https://github.com/fish-shell/fish-shell [screenshot]: http://i.0x7f.us/bobthefish.png diff --git a/fish_prompt.fish b/fish_prompt.fish index 5c4e372..66677e1 100644 --- a/fish_prompt.fish +++ b/fish_prompt.fish @@ -15,6 +15,7 @@ # set -g theme_display_git no # set -g theme_display_git_untracked no # set -g theme_display_git_ahead_verbose yes +# set -g theme_display_vagrant yes # set -g theme_display_hg yes # set -g theme_display_virtualenv no # set -g theme_display_ruby no @@ -47,6 +48,13 @@ set __bobthefish_superscript_glyph \u00B9 \u00B2 \u00B3 set __bobthefish_virtualenv_glyph \u25F0 set __bobthefish_pypy_glyph \u1D56 +# Vagrant glyphs +set __bobthefish_vagrant_running_glyph \u2191 # ↑ 'running' +set __bobthefish_vagrant_poweroff_glyph \u2193 # ↓ 'poweroff' +set __bobthefish_vagrant_aborted_glyph \u2715 # ✕ 'aborted' +set __bobthefish_vagrant_saved_glyph \u21E1 # ⇡ 'saved' +set __bobthefish_vagrant_unknown_glyph '!' # strange cases + # Colors set __bobthefish_lt_green addc10 set __bobthefish_med_green 189303 @@ -71,6 +79,7 @@ set __bobthefish_dk_brown 4d2600 set __bobthefish_med_brown 803F00 set __bobthefish_lt_brown BF5E00 +set __bobthefish_vagrant 48B4FB # =========================== # Helper methods @@ -228,6 +237,38 @@ end # Theme components # =========================== +function __bobthefish_prompt_vagrant -d 'Display Vagrant status' + [ "$theme_display_vagrant" != 'yes' ]; and return + which VBoxManage >/dev/null 2>&1; and set -l __vbox_installed yes + if [ -f Vagrantfile -a "$__vbox_installed" = 'yes' ] + # Get machine UUIDs + set -e __vagrant_ids + set -e __vagrant_statuses + for m in .vagrant/machines/**/id + set -l __machine_id (cat $m) + set __vagrant_ids $__vagrant_ids $__machine_id + end + for i in $__vagrant_ids + set -l __vm_status (VBoxManage showvminfo --machinereadable $i 2>/dev/null | grep 'VMState=' | tr -d '"' | cut -d '=' -f 2) + set __vagrant_statuses "$__vagrant_statuses<$__vm_status>" + end + # Transform statuses to gliphs + set __vagrant_statuses ( echo -n $__vagrant_statuses | sed \ + -e "s##$__bobthefish_vagrant_running_glyph#g" \ + -e "s##$__bobthefish_vagrant_poweroff_glyph#g" \ + -e "s##$__bobthefish_vagrant_aborted_glyph#g" \ + -e "s##$__bobthefish_vagrant_saved_glyph#g" \ + -e "s#<>#$__bobthefish_vagrant_unknown_glyph#g" + ) + # Display status if any status + if [ "$__vagrant_statuses" != '' ] + __bobthefish_start_segment $__bobthefish_vagrant fff --bold + echo -n -s "$__vagrant_statuses " + set_color normal + end + end +end + function __bobthefish_prompt_status -d 'Display symbols for a non zero exit status, root and background jobs' set -l nonzero set -l superuser @@ -475,6 +516,7 @@ end function fish_prompt -d 'bobthefish, a fish theme optimized for awesome' __bobthefish_prompt_status __bobthefish_prompt_vi + __bobthefish_prompt_vagrant __bobthefish_prompt_user __bobthefish_prompt_rubies __bobthefish_prompt_virtualfish From 3e9ce36165abd17472f510a6034189cc16e19593 Mon Sep 17 00:00:00 2001 From: Sasha Egorov Date: Wed, 16 Dec 2015 22:18:18 +0400 Subject: [PATCH 2/2] Typo in comment --- fish_prompt.fish | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fish_prompt.fish b/fish_prompt.fish index 66677e1..9f8b8ba 100644 --- a/fish_prompt.fish +++ b/fish_prompt.fish @@ -252,7 +252,7 @@ function __bobthefish_prompt_vagrant -d 'Display Vagrant status' set -l __vm_status (VBoxManage showvminfo --machinereadable $i 2>/dev/null | grep 'VMState=' | tr -d '"' | cut -d '=' -f 2) set __vagrant_statuses "$__vagrant_statuses<$__vm_status>" end - # Transform statuses to gliphs + # Transform statuses to glyphs set __vagrant_statuses ( echo -n $__vagrant_statuses | sed \ -e "s##$__bobthefish_vagrant_running_glyph#g" \ -e "s##$__bobthefish_vagrant_poweroff_glyph#g" \