From 370d867cc7e0c4155267c87390cd41bcfc0d1d4d Mon Sep 17 00:00:00 2001 From: Sasha Egorov Date: Tue, 27 Oct 2015 22:05:01 +0400 Subject: [PATCH] Title and time --- README.md | 18 ++++++++++----- fish_prompt.fish | 57 ++++++++++++++++++++++++++++++++++++++++++------ fish_title.fish | 19 ++++++++++++++-- 3 files changed, 79 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index e58127b..b8f4c7f 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,11 @@ # bobthefish -bobthefish is a Powerline-style, Git-aware fish theme optimized for awesome. +`bobthefish` is a Powerline-style, Git-aware [fish][fish] theme optimized for awesome. [![](https://img.shields.io/badge/Framework-Oh My Fish-blue.svg?style=flat)](https://github.com/oh-my-fish/oh-my-fish) ![](https://img.shields.io/cocoapods/l/AFNetworking.svg) [![Join the chat at https://gitter.im/oh-my-fish/oh-my-fish](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/oh-my-fish/oh-my-fish?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) ![bobthefish][screenshot] - ### Installation Be sure to have Oh My Fish installed. Then just: @@ -18,7 +17,6 @@ You will probably need a [Powerline-patched font][patching] for this to work. This theme is based loosely on [agnoster][agnoster]. - ### Features * A helpful, but not too distracting, greeting. @@ -29,7 +27,6 @@ This theme is based loosely on [agnoster][agnoster]. * All the things you need to know about Git in a glance. * Visual indication that you can't write to the current directory. - ### The Prompt * Flags: @@ -54,10 +51,9 @@ This theme is based loosely on [agnoster][agnoster]. * _Note that not all of these have been implemented for hg yet :)_ * Abbreviated project-relative path - ### Configuration -You can override some default options in your `config.fish`: +You can override some of the following default options in your `config.fish`: ```fish set -g theme_display_git no @@ -69,12 +65,22 @@ set -g theme_display_ruby no set -g theme_display_user yes set -g theme_title_display_process yes set -g theme_title_display_path no +set -g theme_title_use_abbreviated_path no set -g theme_date_format "+%a %H:%M" set -g theme_avoid_ambiguous_glyphs yes set -g default_user your_normal_user ``` +**Title options** +- `theme_title_display_process`. By default theme doesn't show current process name in terminal title. If you want to show it, just set to `yes`. +- `theme_title_display_path`. Use `no` to hide current working directory from title. +- `theme_title_use_abbreviated_path`. Default is `yes`. This means your home directory will be displayed as `~` and `/usr/local` as `/u/local`. Set it to `no` if you prefer full paths in title. + +**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. + +[fish]: https://github.com/fish-shell/fish-shell [screenshot]: http://i.0x7f.us/bobthefish.png [patching]: https://powerline.readthedocs.org/en/latest/fontpatching.html [fonts]: https://github.com/Lokaltog/powerline-fonts diff --git a/fish_prompt.fish b/fish_prompt.fish index ac825a4..deddc6b 100644 --- a/fish_prompt.fish +++ b/fish_prompt.fish @@ -2,7 +2,7 @@ # # bobthefish is a Powerline-style, Git-aware fish theme optimized for awesome. # -# You will probably need a Powerline-patched font for this to work: +# You will need a Powerline-patched font for this to work: # # https://powerline.readthedocs.org/en/latest/fontpatching.html # @@ -10,7 +10,7 @@ # # https://github.com/Lokaltog/powerline-fonts # -# You can override some default options in your config.fish: +# You can override some default prompt options in your config.fish: # # set -g theme_display_git no # set -g theme_display_git_untracked no @@ -19,8 +19,6 @@ # set -g theme_display_virtualenv no # set -g theme_display_ruby no # set -g theme_display_user yes -# set -g theme_title_display_process yes -# set -g theme_title_display_path no # set -g theme_date_format "+%a %H:%M" # set -g theme_avoid_ambiguous_glyphs yes # set -g default_user your_normal_user @@ -391,10 +389,51 @@ function __bobthefish_prompt_virtualfish -d "Display activated virtual environme set_color normal end -function __bobthefish_prompt_rubies -d 'Display current Ruby (rvm/rbenv)' - [ "$theme_display_ruby" = 'no' ]; and return +function __bobthefish_rvm_parse_ruby -a ruby_string scope -d 'Parse RVM Ruby string' + # Function arguments: + # - 'ruby-2.2.3@rails', 'jruby-1.7.19'... + # - 'default' or 'current' + set -l __ruby (echo $ruby_string | cut -d '@' -f 1 2>/dev/null) + set -g __rvm_{$scope}_ruby_interpreter (echo $__ruby | cut -d '-' -f 1 2>/dev/null) + set -g __rvm_{$scope}_ruby_version (echo $__ruby | cut -d '-' -f 2 2>/dev/null) + set -g __rvm_{$scope}_ruby_gemset (echo $ruby_string | cut -d '@' -f 2 2>/dev/null) + [ "$__ruby_gemset" = "$__ruby" ]; and set -l __ruby_gemset global +end + +function __bobthefish_rvm_info -d 'Current Ruby information from RVM' + # More `sed`/`grep`/`cut` magic... + set -l __rvm_default_ruby (grep GEM_HOME ~/.rvm/environments/default | \ + sed -e"s/'//g" | sed -e's/.*\///') + set -l __rvm_current_ruby (rvm-prompt i v g) + # Parse default and current Rubies to global variables + __bobthefish_rvm_parse_ruby $__rvm_default_ruby default + __bobthefish_rvm_parse_ruby $__rvm_current_ruby current + # Show unobtrusive RVM prompt + if [ "$__rvm_default_ruby" = "$__rvm_current_ruby" ]; return + # If interpreter differs form default interpreter, show everything: + else if [ "$__rvm_default_ruby_interpreter" != "$__rvm_current_ruby_interpreter" ] + if [ "$__rvm_current_ruby_gemset" = 'global' ]; rvm-prompt i v + else; rvm-prompt i v g; end + # If version differs form default version + else if [ "$__rvm_default_ruby_version" != "$__rvm_current_ruby_version" ] + if [ "$__rvm_current_ruby_gemset" = 'global' ]; rvm-prompt v + else; rvm-prompt v g; end + # If gemset differs form default or 'global' gemset, just show it + else if [ "$__rvm_default_ruby_gemset" != "$__rvm_current_ruby_gemset" ] + rvm-prompt g; + end + set --erase --global __rvm_current_ruby_gemset + set --erase --global __rvm_current_ruby_interpreter + set --erase --global __rvm_current_ruby_version + set --erase --global __rvm_default_ruby_gemset + set --erase --global __rvm_default_ruby_interpreter + set --erase --global __rvm_default_ruby_version +end + +function __bobthefish_show_ruby -d 'Current Ruby (rvm/rbenv)' + set -l ruby_version if which rvm-prompt >/dev/null 2>&1 - set ruby_version (rvm-prompt i v g) + set ruby_version (__bobthefish_rvm_info) else if which rbenv >/dev/null 2>&1 set ruby_version (rbenv version-name) # Don't show global ruby version... @@ -407,6 +446,10 @@ function __bobthefish_prompt_rubies -d 'Display current Ruby (rvm/rbenv)' set_color normal end +function __bobthefish_prompt_rubies -d 'Display current Ruby information' + [ "$theme_display_ruby" = 'no' ]; and return + __bobthefish_show_ruby +end # =========================== # Apply theme diff --git a/fish_title.fish b/fish_title.fish index 460cd6a..43d18c9 100644 --- a/fish_title.fish +++ b/fish_title.fish @@ -1,4 +1,19 @@ +# You can override some default title options in your config.fish: +# set -g theme_title_display_process no +# set -g theme_title_display_path no +# set -g theme_title_use_abbreviated_path no + function fish_title - [ "$theme_title_display_process" = 'yes' ]; and echo $_ ' ' - [ "$theme_title_display_path" != 'no' ]; and prompt_pwd + if [ "$theme_title_display_process" = 'yes' ] + echo $_ + [ "$theme_title_display_path" != 'no' ]; and echo ' ' + end + + if [ "$theme_title_display_path" != 'no' ] + if [ "$theme_title_use_abbreviated_path" = 'no' ] + echo $PWD + else + prompt_pwd + end + end end