#+title: fish config #+PROPERTY: header-args :tangle config.fish * Intro This is the fish config I use. It's largely a copy of [[https://gitlab.com/dwt1][Derek Taylor's]] [[https://gitlab.com/dwt1/dotfiles/-/blob/master/.config/fish/config.fish][fish config.]] I have some edits in, but it's nothing significant. The majority of the comments are Derek's. * Path First line removes the path; second line sets it. Without the first line, your path gets massive and fish becomes very slow. #+begin_src fish set -e fish_user_paths set -U fish_user_paths $HOME/apps/bin $HOME/.local/bin $HOME/Applications $HOME/.cabal/bin $HOME/.ghcup/bin $HOME/.deno/bin $fish_user_paths set -U EDITOR emacsclient -c --alternate-editor='' set -Ux PASSWORD_STORE_DIR $HOME/enc/keys/pass/ set -U PLANTUML_LIMIT_SIZE 16384 set -e SSH_AGENT_PID if not set -q gnupg_SSH_AUTH_SOCK_by or test $gnupg_SSH_AUTH_SOCK_by -ne $fish_pid set -gx SSH_AUTH_SOCK (gpgconf --list-dirs agent-ssh-socket) end #+end_src * Exports #+begin_src fish set fish_greeting set TERM "xterm-256color" set EDITOR "emacsclient -t -a ''" set VISUAL "emacsclient -c -a emacs" set QT_QPA_PLATFORMTHEME "qt6ct" set SSH_AUTH_SOCK $XDG_RUNTIME_DIR/ssh-agent.socket set GNUPGHOME "~/enc/keys/gnupg" set LEDGER_FILE "~/enc/org/hledger/2023.journal" #+end_src * Manpager There are several options: - bat: ~set -x MANPAGER "sh -c 'col -bx | bat -l man -p'"~ - vim: ~set -x MANPAGER '/bin/bash -c "vim -MRn -c \"set buftype=nofile showtabline=0 ft=man ts=8 nomod nolist norelativenumber nonu noma\" -c \"normal L\" -c \"nmap q :qa\" --max=] Draw sparklines" echo "examples:" echo " spark 1 2 3 4" echo " seq 100 | sort -R | spark" echo " awk \\\$0=length spark.fish | spark" case \* echo $argv | spark $argv end return end command awk -v FS="[[:space:],]*" -v argv="$argv" ' BEGIN { min = match(argv, /--min=[0-9]+/) ? substr(argv, RSTART + 6, RLENGTH - 6) + 0 : "" max = match(argv, /--max=[0-9]+/) ? substr(argv, RSTART + 6, RLENGTH - 6) + 0 : "" } { for (i = j = 1; i <= NF; i++) { if ($i ~ /^--/) continue if ($i !~ /^-?[0-9]/) data[count + j++] = "" else { v = data[count + j++] = int($i) if (max == "" && min == "") max = min = v if (max < v) max = v if (min > v ) min = v } } count += j - 1 } END { n = split(min == max && max ? "▅ ▅" : "▁ ▂ ▃ ▄ ▅ ▆ ▇ █", blocks, " ") scale = (scale = int(256 * (max - min) / (n - 1))) ? scale : 1 for (i = 1; i <= count; i++) out = out (data[i] == "" ? " " : blocks[idx = int(256 * (data[i] - min) / scale) + 1]) print out } ' end #+end_src *** Spark functions #+begin_src fish function letters cat $argv | awk -vFS='' '{for(i=1;i<=NF;i++){ if($i~/[a-zA-Z]/) { w[tolower($i)]++} } }END{for(i in w) print i,w[i]}' | sort | cut -c 3- | spark | lolcat printf '%s\n' 'abcdefghijklmnopqrstuvwxyz' ' ' | lolcat end function commits git log --author="$argv" --format=format:%ad --date=short | uniq -c | awk '{print $1}' | spark | lolcat end #+end_src ** !! and !$ *** Functions for !! and !$ #+begin_src fish function __history_previous_command switch (commandline -t) case "!" commandline -t $history[1]; commandline -f repaint case "*" commandline -i ! end end function __history_previous_command_arguments switch (commandline -t) case "!" commandline -t "" commandline -f history-token-search-backward case "*" commandline -i '$' end end #+end_src *** Bindings for !! and !$ #+begin_src fish if [ $fish_key_bindings = "fish_vi_key_bindings" ]; bind -Minsert ! __history_previous_command bind -Minsert '$' __history_previous_command_arguments else bind ! __history_previous_command bind '$' __history_previous_command_arguments end #+end_src ** Small functions *** backup Creates a $filename.bak copy of the argument file. #+begin_src fish function backup --argument filename cp $filename $filename.bak end #+end_src *** copy Copy things, recursively. Like ~cp -r~. #+begin_src fish function copy set count (count $argv | tr -d \n) if test "$count" = 2; and test -d "$argv[1]" set from (echo $argv[1] | trim-right /) set to (echo $argv[2]) command cp -r $from $to else command cp $argv end end #+end_src *** coln Print only one column of the output. #+begin_src fish function coln while read -l input echo $input | awk '{print $'$argv[1]'}' end end #+end_src *** rown Print only one row of the output. #+begin_src fish function rown --argument index sed -n "$index p" end #+end_src *** skip Skips ~n~ lines of the output. #+begin_src fish function skip --argument n tail +(math 1 + $n) end #+end_src *** take Prints only the first ~n~ lines of the output. #+begin_src fish function take --argument number head -$number end #+end_src *** org-search Perform a search through your ~org-agenda-files~ for a ~string~. #+begin_src fish function org-search -d "send a search string to org-mode" set -l output (/usr/bin/emacsclient -a "" -e "(message \"%s\" (mapconcat #'substring-no-properties \ (mapcar #'org-link-display-format \ (org-ql-query \ :select #'org-get-heading \ :from (org-agenda-files) \ :where (org-ql--query-string-to-sexp \"$argv\"))) \ \" \"))") printf $output end #+end_src * Aliases ** clear Clears the terminal and prints some decorations. #+begin_src fish alias clear='/bin/clear; echo; echo; seq 1 (tput cols) | sort -R | spark | lolcat; echo; echo' #+end_src ** doas Sets root privileges for the command. #+begin_src fish alias doas="doas --" #+end_src ** cd shorts Helps navigate directory trees without typing lots of dots. #+begin_src fish alias ..='cd ..' alias ...='cd ../..' alias .3='cd ../../..' alias .4='cd ../../../..' alias .5='cd ../../../../..' #+end_src ** vim #+begin_src fish alias vim='nvim' #+end_src ** exa These bindings change the way ~ls~ behaves by calling ~exa~ instead. #+begin_src fish alias ls='exa -al --color=always --group-directories-first' alias la='exa -a --color=always --group-directories-first' alias ll='exa -l --color=always --group-directories-first' alias lt='exa -aT --color=always --group-directories-first' alias l.='exa -a | egrep "^\."' #+end_src ** pacman Aliases for common ~pacman~ commands. *** pacsyu Updates only ~pacman~ (core Arch repo) packages. #+begin_src fish alias pacsyu='sudo pacman -Syyu' #+end_src *** parsua Updates only AUR packages with ~paru~. #+begin_src fish alias parsua='paru -Sua --noconfirm' #+end_src *** parsyu Updates everything with ~paru~. Note the ~--sudoloop~ argument - it allows for unattended upgrades. Won't halt the process if you go and get coffee. #+begin_src fish alias parsyu='paru -Syu --noconfirm --sudoloop' #+end_src *** unlock Removes ~pacman~'s lockfile. #+begin_src fish alias unlock='sudo rm /var/lib/pacman/db.lck' #+end_src *** cleanup Removes orphaned packages. #+begin_src fish alias cleanup='sudo pacman -Rns (pacman -Qtdq)' #+end_src *** mirror Aliases for ~reflector~, finding the fastest mirrors to get packages from. #+begin_src fish alias mirror="sudo reflector -f 30 -l 30 --number 10 --verbose --save /etc/pacman.d/mirrorlist" alias mirrord="sudo reflector --latest 50 --number 20 --sort delay --save /etc/pacman.d/mirrorlist" alias mirrors="sudo reflector --latest 50 --number 20 --sort score --save /etc/pacman.d/mirrorlist" alias mirrora="sudo reflector --latest 50 --number 20 --sort age --save /etc/pacman.d/mirrorlist" #+end_src ** grep Add colors to ~grep~ output. #+begin_src fish alias grep='grep --color=auto' alias egrep='egrep --color=auto' alias fgrep='fgrep --color=auto' #+end_src ** cp, mv, rm Ask for confirmation before overwriting files. #+begin_src fish alias cp="cp -i" alias mv='mv -i' #+end_src ** df, free Make the output human-readable by default. #+begin_src fish alias df='df -h' alias free='free -m' #+end_src ** ps Some handy shortcuts for ~ps~. #+begin_src fish alias psa="ps auxf" alias psgrep="ps aux | grep -v grep | grep -i -e VSZ -e" alias psmem='ps auxf | sort -nr -k 4' alias pscpu='ps auxf | sort -nr -k 3' #+end_src ** merge Merges ~~/.Xresources~. #+begin_src fish alias merge='xrdb -merge ~/.Xresources' #+end_src ** git #+begin_src fish alias addup='git add -u' alias addall='git add .' alias branch='git branch' alias checkout='git checkout' alias clone='git clone' alias commit='git commit -m' alias fetch='git fetch' alias pull='git pull origin' alias push='git push origin' alias tag='git tag' alias newtag='git tag -a' #+end_src ** jctl Get error messages from ~journalctl~. #+begin_src fish alias jctl="journalctl -p 3 -xb" #+end_src ** gpg *** gpg-check Verify signature. #+begin_src fish alias gpg-check="gpg2 --keyserver-options auto-key-retrieve --verify" #+end_src *** gpg-retrieve Retrieve gpg keys. #+begin_src fish alias gpg-retrieve="gpg2 --keyserver-options auto-key-retrieve --receive-keys" #+end_src ** yta ~youtube-dl~ shortcuts. #+begin_src fish alias yta-aac="youtube-dl --extract-audio --audio-format aac " alias yta-best="youtube-dl --extract-audio --audio-format best " alias yta-flac="youtube-dl --extract-audio --audio-format flac " alias yta-m4a="youtube-dl --extract-audio --audio-format m4a " alias yta-mp3="youtube-dl --extract-audio --audio-format mp3 " alias yta-opus="youtube-dl --extract-audio --audio-format opus " alias yta-vorbis="youtube-dl --extract-audio --audio-format vorbis " alias yta-wav="youtube-dl --extract-audio --audio-format wav " alias ytv-best="youtube-dl -f bestvideo+bestaudio " #+end_src ** shell Aliases to switch your login shell. Why would you do this... I can't fathom. #+begin_src fish alias tobash="sudo chsh $USER -s /bin/bash && echo 'Now log out.'" alias tozsh="sudo chsh $USER -s /bin/zsh && echo 'Now log out.'" alias tofish="sudo chsh $USER -s /bin/fish && echo 'Now log out.'" #+end_src ** config :noexport: Bare git repo for dotfiles. /Note:/ No longer in use, since I moved to using stow instead. See the main readme file in the root directory of this git repo. #+begin_src fish :tangle no alias config="/usr/bin/git --git-dir=$HOME/git/dot --work-tree=$HOME" #+end_src ** tb ~termbin~ in your terminal. #+begin_src fish alias tb="nc termbin.com 9999" #+end_src ** tips I'm not sure what this does. Derek's comment is ~Unlock LBRY tips~, which honestly can mean anything. Leaving this in my config just in case it's important. #+begin_src fish alias tips="lbrynet txo spend --type=support --is_not_my_input --blocking" #+end_src * DTOS These are things that I tend to keep in after first installing DTOS on top of Arch. I don't need much afterwards, so a lot of it is missing. For the full deal, head to Derek's repo, where you can see all the aliases and settings. ** Pretty! *** colorscript You can get this script from [[gitlab.com/dwt1/shell-color-scripts][DT's git,]] or install them from AUR: ~shell-color-scripts~. #+begin_src fish colorscript random #+end_src *** starship prompt #+begin_src fish starship init fish | source #+end_src ** Environment variables #+begin_src fish set -gx PATH "$HOME/.cabal/bin:$HOME/.ghcup/bin:$PATH" #+end_src * Phil's stuff ** phil-fix-names Makes directory and file names lowercase, substitutes whitespace for dashes. #+begin_src fish function phil-fix-names perl-rename 'y/A-Z/a-z/' * && perl-rename 'y/ /-/' * end #+end_src ** polish Occasionally my keyboard layout changes. I have not figured out why yet, but this way I can quickly reset it. #+begin_src fish function polish setxkbmap -model pc104 -layout pl -option compose:rctrl end #+end_src ** greek Occasionally I type in greek. This function sets my keyboard layout for it. #+begin_src fish function greek setxkbmap -model pc104 -layout gr -option compose:rctrl end #+end_src ** vps Logs me into my VPS with an ssh key. I use it extensively, so being able to log in without having to type a password is really nice. #+begin_src fish function vps ssh -p 2222 phil@46.38.232.163 -i ~/.ssh/id_ed25519_nopass end #+end_src ** vpssh Mounts my \/srv\/ directory into ~/remote/vps-srv. Really convenient. My websites all run on org-mode, so this makes it very easy to work on them from the convenience of the best text editor. #+begin_src fish function vpssh sshfs phil@46.38.232.163:/srv/ ~/remote/vps-srv -p 2222 -o identityFile=~/.ssh/id_ed25519_nopass -o reconnect end #+end_src ** vpsshu Unmounts the above. #+begin_src fish function vpsshu fusermount3 -u ~/remote/vps-srv/ end #+end_src