Fish Shell (Friendly Interactive Shell) is a modern shell tool designed to provide a simpler and more user-friendly command line environment, featuring auto-completion, syntax highlighting, and a more friendly user interface.
Fish Shell (Friendly Interactive Shell)#
- Install the latest version of Fish Shell
sudo apt-add-repository ppa:fish-shell/release-3
sudo apt update
sudo apt install fish
- Set Fish Shell as the default shell
cat /etc/shells # View all shells
chsh -s /usr/bin/fish
- Reopen the terminal
Starship - A lightweight, fast, and infinitely customizable beautiful terminal!#
If you are using a terminal like Windows Terminal or VS Code, you need to install a Nerd Font font and enable it in the terminal (for example, you can try using the Fira Code Nerd Font font).
Installation tutorial: https://zhuanlan.zhihu.com/p/467581369
The theme I am using is Pastel Powerline Preset
fzf - The ideal companion for Fish Shell#
- First, install fzf
git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf # Get the latest version of fzf
~/.fzf/install # Install fzf
- (Optional) Use the plugin manager fisher to install fzf.fish
curl -sL https://raw.githubusercontent.com/jorgebucaran/fisher/main/functions/fisher.fish | source && fisher install jorgebucaran/fisher # Install fisher
fisher install jethrokuan/fzf
- You can now operate fzf using the following shortcuts
Default fzf Shortcut | New Shortcut | Notes |
---|---|---|
Ctrl-t | Ctrl-o | Find files |
Ctrl-r | Ctrl-r | Find command history |
Alt-c | Alt-c | Open subdirectory (recursive search) |
Alt-Shift-c | Alt-Shift-c | Open subdirectory (hidden folders) |
Ctrl-o | Alt-o | Open file/directory with default editor ($EDITOR) |
Ctrl-g | Alt-Shift-o | Open file/directory with xdg-open or open command |
- Implement a quick directory jump
fzf has a very high degree of freedom, allowing you to write scripts to achieve many interesting features, such as implementing a directory jump function that can be used in the command line, instead of having to ls after every cd into a directory.
- Create a fzf_directory.fish
vim ~/.fzf/shell/fzf_directory.fish
Then write the following code
#!/usr/bin/fish
function fzf-getpath --description "Get path to current directory"
# set -U rpath_cwd_v1 (pwd)
# Main function to move forward/backward through paths
# function get_path
set -l main $argv[1]
set -l relative_index $argv[2]
set -l prefix $argv[3]
if test $main -eq 1
set -U rpath_cwd_v1 (pwd)
echo $rpath_cwd_v1
find $rpath_cwd_v1 -maxdepth 1 -type d -printf '%f\n' | tail -n +2 | sort
else if test $main -eq 0
if test $prefix != $rpath_cwd_v1
if test $relative_index -eq 1
if test $rpath_cwd_v1 = "/"
set -U rpath_cwd_v1 /$prefix
else
set -U rpath_cwd_v1 $rpath_cwd_v1/$prefix
end
echo $rpath_cwd_v1
find $rpath_cwd_v1 -maxdepth 1 -type d -printf '%f\n' | tail -n +2 | sort
else if test $relative_index -eq -1
set -U rpath_cwd_v1 (dirname $rpath_cwd_v1)
echo $rpath_cwd_v1
find $rpath_cwd_v1 -maxdepth 1 -type d -printf '%f\n' | tail -n +2 | sort
end
else
echo $rpath_cwd_v1
find $rpath_cwd_v1 -maxdepth 1 -type d -printf '%f\n' | tail -n +2 | sort
end
else
set -g rpath_temp $rpath_cwd_v1
if test -n $prefix && test $prefix != $rpath_cwd_v1
set -g rpath_temp $rpath_cwd_v1/$prefix
end
echo $rpath_temp
end
end
function fzf-routepath --description "Change directory"
set -l result (fzf-getpath 1 0 '' | fzf --height=85% --prompt 'Directories> ' --layout=reverse --info=inline --border --margin=1 --padding=1 --preview 'tree -L 2 -C (fish -C "fzf-getpath -1 0 {}")' --bind 'right:reload(fzf-getpath 0 1 {})' --bind 'left:reload(fzf-getpath 0 -1 /)' --bind 'enter:become(fzf-getpath -1 0 {})' --bind 'esc:become(pwd)' )
if [ -n "$result" ]
cd -- $result
# Remove last token from command line.
commandline -t ""
commandline -it -- $prefix
end
commandline -f repaint
end
bind \ed fzf-routepath # Bind fzf-routepath to Alt-D
- Activate when starting Fish Shell
In
echo "source ~/.fzf/shell/fzf_directory.fish" >> ~/.config/fish/config.fish
source ~/.config/fish/config.fish
- Press Alt D to open the fzf page, use the left and right keys to enter and exit directories, press enter to cd into a directory, and the right window can preview the directory contents.
Once configured, it is very enjoyable to use.