Skip to content

Instantly share code, notes, and snippets.

@Wtower
Last active October 20, 2022 21:47
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Wtower/970bf009f0a9c3b0733a to your computer and use it in GitHub Desktop.
Save Wtower/970bf009f0a9c3b0733a to your computer and use it in GitHub Desktop.
Using fish shell with python virtualenv, node nvm and ansible
# Greeting prologue
echo "Welcome to "(uname -a | awk '{print $1 " " $2 " " $3 " " $4 " " $12}')
uptime
# ansible
. ~/workspace/ansible/ansible/hacking/env-setup.fish -q > /dev/null ^&1
set -Ux ANSIBLE_INVENTORY ~/workspace/ansible/play/hosts
echo "Now using "(ansible --version | head -n 1 | awk '{print $1 " " $2}')
# Load virtual fish
echo "Now using vf"
eval (python -m virtualfish compat_aliases auto_activation)
# Change prompt
functions -c fish_prompt _old_fish_prompt
function fish_prompt
if set -q VIRTUAL_ENV
echo -n -s (set_color -b blue white) "(" (basename "$VIRTUAL_ENV") ")" (set_color normal) " "
end
_old_fish_prompt
end
# nvm
. ~/.config/fish/nvm-wrapper/nvm.fish
nvm use default
# for karma:
set -x CHROME_BIN /usr/bin/chromium-browser
# Fish greeting
echo "Now using fish $FISH_VERSION"
function fish_greeting
fortune
end

Using fish with virtualenv, nvm and ansible

Fish is an excellent shell. Its amazing suggestions and simplicity make it the next-gen bash. Nevertheless the traditional virtualenvwrapper and nvm do not work immediately with it. A small extra configuration is required, but it is worth the time since they offer better features such as auto-activation when changing to a project directory.

Fish and virtualenv

The project virtual fish is the solution for virtualenvs. The installation guide occasionaly caused some issues, therefore the following installation guide is recommended:

Install fish v2.0+ (1.x won't work, check with the OS repos or fish -version). Also make sure that virtualenv is installed. Then install virtual fish:

pip install virtualfish

Then edit the configuration file (see section below).

Fish and nvm

The project nvm-fish-wrapper is the solution for nvm. The installation guide has an error, therefore the following installation guide is recommended:

Make sure nvm is installed. Then:

cd ~/.config/fish
git clone git://github.com/passcod/nvm-fish-wrapper.git nvm-wrapper

Then edit the configuration file:

Configuration file

Edit ~/.config/fish/config.fish. A suggestion is included in separate file below. Description:

  • A small greeting prologue displaying OS info
  • Ansible: load ansible env setup before loading virtual fish and potentially automatically connecting to a separate virtualenv
  • Run virtual fish: as explained by the documentation. Customize the plugins as required.
  • Change prompt: there the default documentation was inadequate, see relevant link
  • Nvm: source nvm wrapper. Again the default documentation has a mistake there (source is bash only).
  • Fish greeting: a simple function to change the greeting when starting fish. See Suppress or Customize Intro Message in Fish Shell.

Example output

Welcome to Linux rodope 3.19.0-51-generic #58-Ubuntu x86_64
 11:50:08 up  2:29,  2 users,  load average: 0,19, 0,52, 0,66
Now using ansible 2.1.0
Now using vf
Now using node v0.12.10
Now using fish 2.1.1
You attempt things that you do not even plan because of your extreme stupidity.
wtower@rodope ~> 

Changing default shell in Ubuntu

Bash:

chsh -s `which fish`

Fish:

chsh -s (which fish)

May require restart.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment