Fish on Cloudshell
Fish is described as a smart and user-friendly command shell. As you would expect it works on Linux and is super useful to get that optimized experience. The blog post covers installation on GCP Cloud Shell I would expect the installation process to be similar on any Linux based machine.
If you want to use oh-my-bash, read a previous post on using Cloud Shell with oh-my-bash
You are good to go!
Installation
- Open Cloud Shell in the Google Cloud console
- Install the Fish package by typing:
1sudo apt install fish
- Once installed, at the command line type:
1fish
Nice you are now using the fish application in Cloud Shell
Useful command prompt
Fish configuration is performed using a web portal.
Running the configuration app uses Port 8000.
Unfortunately this doesnt appear to work in Cloud Shell.
However just need the generated files.
The following function provides a basic prompt for git
- Make a new subdirectory
1mkdir -p ~.config/fish/functions
- Add the above function to ~/.config/fish/functions/fish_prompt.fish
1function fish_prompt
2 set -l __last_command_exit_status $status
3
4 if not set -q -g __fish_robbyrussell_functions_defined
5 set -g __fish_robbyrussell_functions_defined
6 function _git_branch_name
7 set -l branch (git symbolic-ref --quiet HEAD 2>/dev/null)
8 if set -q branch[1]
9 echo (string replace -r '^refs/heads/' '' $branch)
10 else
11 echo (git rev-parse --short HEAD 2>/dev/null)
12 end
13 end
14
15 function _is_git_dirty
16 echo (git status -s --ignore-submodules=dirty 2>/dev/null)
17 end
18
19 function _is_git_repo
20 type -q git
21 or return 1
22 git rev-parse --git-dir >/dev/null 2>&1
23 end
24
25 function _hg_branch_name
26 echo (hg branch 2>/dev/null)
27 end
28
29 function _is_hg_dirty
30 echo (hg status -mard 2>/dev/null)
31 end
32
33 function _is_hg_repo
34 fish_print_hg_root >/dev/null
35 end
36
37 function _repo_branch_name
38 _$argv[1]_branch_name
39 end
40
41 function _is_repo_dirty
42 _is_$argv[1]_dirty
43 end
44
45 function _repo_type
46 if _is_hg_repo
47 echo 'hg'
48 return 0
49 else if _is_git_repo
50 echo 'git'
51 return 0
52 end
53 return 1
54 end
55 end
56
57 set -l cyan (set_color -o cyan)
58 set -l yellow (set_color -o yellow)
59 set -l red (set_color -o red)
60 set -l green (set_color -o green)
61 set -l blue (set_color -o blue)
62 set -l normal (set_color normal)
63
64 set -l arrow_color "$green"
65 if test $__last_command_exit_status != 0
66 set arrow_color "$red"
67 end
68
69 set -l arrow "$arrow_color➜ "
70 if test "$USER" = 'root'
71 set arrow "$arrow_color# "
72 end
73
74 set -l cwd $cyan(basename (prompt_pwd))
75
76 if set -l repo_type (_repo_type)
77 set -l repo_branch $red(_repo_branch_name $repo_type)
78 set repo_info "$blue $repo_type:($repo_branch$blue)"
79
80 if [ (_is_repo_dirty $repo_type) ]
81 set -l dirty "$yellow ✗"
82 set repo_info "$repo_info$dirty"
83 end
84 end
85
86 echo -n -s $arrow ' '$cwd $repo_info $normal ' '
87end
Other settings
If you want to generate other functions/settings, try running fish on your local machine to grab the config.
- The command to use is:
1fish_config
- Open the browser e.g.
http://localhost:8000
- Select the configuration options required
- Add the generated file(s) across to Cloud Shell.