Debin

Debin

Tool Section: Fish Shell — A Simpler and More User-Friendly Shell

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-2024-09-21-19-25-58

Fish Shell (Friendly Interactive Shell)#

  1. Install the latest version of Fish Shell
sudo apt-add-repository ppa:fish-shell/release-3
sudo apt update
sudo apt install fish
  1. Set Fish Shell as the default shell
cat /etc/shells # View all shells
chsh -s /usr/bin/fish 
  1. Reopen the terminal

Starship - A lightweight, fast, and infinitely customizable beautiful terminal!#

【Installation Guide】

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

fish-shell-2024-09-21-19-48-59

fzf - The ideal companion for Fish Shell#

  1. First, install fzf
git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf # Get the latest version of fzf
~/.fzf/install # Install fzf
  1. (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
  1. You can now operate fzf using the following shortcuts
Default fzf ShortcutNew ShortcutNotes
Ctrl-tCtrl-oFind files
Ctrl-rCtrl-rFind command history
Alt-cAlt-cOpen subdirectory (recursive search)
Alt-Shift-cAlt-Shift-cOpen subdirectory (hidden folders)
Ctrl-oAlt-oOpen file/directory with default editor ($EDITOR)
Ctrl-gAlt-Shift-oOpen file/directory with xdg-open or open command
  1. 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.

  1. 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
  1. Activate when starting Fish Shell

In

echo "source ~/.fzf/shell/fzf_directory.fish" >> ~/.config/fish/config.fish
source ~/.config/fish/config.fish
  1. 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.
    fish-shell-2024-09-21-20-38-50

Once configured, it is very enjoyable to use.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.