.. | ||
functions | ||
config.fish | ||
fish_variables | ||
README.org |
fish config
- Intro
- Path
- Exports
- Manpager
- Text editing mode:
- Autocomplete and highlight colors
- Functions
- Aliases
- DTOS
- Phil's stuff
Intro
This is the fish config I use. It's largely a copy of Derek Taylor's 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.
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 $HOME/.cargo/bin
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
Exports
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"
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<CR>\"</dev/tty <(col -b)"'
- nvim:
set -x MANPAGER "nvim -c 'set ft=man' -"
set -x MANPAGER "sh -c 'col -bx | bat -l man -p'"
Text editing mode:
You can choose between:
- emacs mode:
fish_default_key_bindings
- vi mode:
fish_vi_key_bindings
function fish_user_key_bindings
fish_default_key_bindings
end
Autocomplete and highlight colors
set fish_color_normal brcyan
set fish_color_autosuggestion '#7d7d7d'
set fish_color_command brcyan
set fish_color_error '#ff6c6b'
set fish_color_param brcyan
Functions
Spark
Definitions
set -g spark_version 1.0.0
complete -xc spark -n __fish_use_subcommand -a --help -d "Show usage help"
complete -xc spark -n __fish_use_subcommand -a --version -d "$spark_version"
complete -xc spark -n __fish_use_subcommand -a --min -d "Minimum range value"
complete -xc spark -n __fish_use_subcommand -a --max -d "Maximum range value"
function spark -d "sparkline generator"
if isatty
switch "$argv"
case {,-}-v{ersion,}
echo "spark version $spark_version"
case {,-}-h{elp,}
echo "usage: spark [--min=<n> --max=<n>] <numbers...> 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
Spark functions
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
!! and !$
Functions for !! and !$
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
Bindings for !! and !$
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
Small functions
backup
Creates a $filename.bak copy of the argument file.
function backup --argument filename
cp $filename $filename.bak
end
copy
Copy things, recursively. Like cp -r
.
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
coln
Print only one column of the output.
function coln
while read -l input
echo $input | awk '{print $'$argv[1]'}'
end
end
rown
Print only one row of the output.
function rown --argument index
sed -n "$index p"
end
skip
Skips n
lines of the output.
function skip --argument n
tail +(math 1 + $n)
end
take
Prints only the first n
lines of the output.
function take --argument number
head -$number
end
org-search
Perform a search through your org-agenda-files
for a string
.
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
Aliases
clear
Clears the terminal and prints some decorations.
alias clear='/bin/clear; echo; echo; seq 1 (tput cols) | sort -R | spark | lolcat; echo; echo'
doas
Sets root privileges for the command.
alias doas="doas --"
cd shorts
Helps navigate directory trees without typing lots of dots.
alias ..='cd ..'
alias ...='cd ../..'
alias .3='cd ../../..'
alias .4='cd ../../../..'
alias .5='cd ../../../../..'
vim
alias vim='nvim'
exa
These bindings change the way ls
behaves by calling exa
instead.
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 "^\."'
pacman
Aliases for common pacman
commands.
pacsyu
Updates only pacman
(core Arch repo) packages.
alias pacsyu='sudo pacman -Syyu'
parsua
Updates only AUR packages with paru
.
alias parsua='paru -Sua --noconfirm'
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.
alias parsyu='paru -Syu --noconfirm --sudoloop'
unlock
Removes pacman
's lockfile.
alias unlock='sudo rm /var/lib/pacman/db.lck'
cleanup
Removes orphaned packages.
alias cleanup='sudo pacman -Rns (pacman -Qtdq)'
mirror
Aliases for reflector
, finding the fastest mirrors to get packages from.
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"
grep
Add colors to grep
output.
alias grep='grep --color=auto'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
cp, mv, rm
Ask for confirmation before overwriting files.
alias cp="cp -i"
alias mv='mv -i'
df, free
Make the output human-readable by default.
alias df='df -h'
alias free='free -m'
ps
Some handy shortcuts for ps
.
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'
merge
Merges ~/.Xresources
.
alias merge='xrdb -merge ~/.Xresources'
git
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'
jctl
Get error messages from journalctl
.
alias jctl="journalctl -p 3 -xb"
gpg
gpg-check
Verify signature.
alias gpg-check="gpg2 --keyserver-options auto-key-retrieve --verify"
gpg-retrieve
Retrieve gpg keys.
alias gpg-retrieve="gpg2 --keyserver-options auto-key-retrieve --receive-keys"
yta
youtube-dl
shortcuts.
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 "
shell
Aliases to switch your login shell. Why would you do this… I can't fathom.
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.'"
tb
termbin
in your terminal.
alias tb="nc termbin.com 9999"
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.
alias tips="lbrynet txo spend --type=support --is_not_my_input --blocking"
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 DT's git, or install them from AUR: shell-color-scripts
.
colorscript random
starship prompt
starship init fish | source
Environment variables
set -gx PATH "$HOME/.cabal/bin:$HOME/.ghcup/bin:$PATH"
Phil's stuff
phil-fix-names
Makes directory and file names lowercase, substitutes whitespace for dashes.
function phil-fix-names
perl-rename 'y/A-Z/a-z/' * && perl-rename 'y/ /-/' *
end
polish
Occasionally my keyboard layout changes. I have not figured out why yet, but this way I can quickly reset it.
function polish
setxkbmap -model pc104 -layout pl -option compose:rctrl
end
greek
Occasionally I type in greek. This function sets my keyboard layout for it.
function greek
setxkbmap -model pc104 -layout gr -option compose:rctrl
end
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.
function vps
ssh -p 2222 phil@46.38.232.163 -i ~/.ssh/id_ed25519_nopass
end
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.
function vpssh
sshfs phil@46.38.232.163:/srv/ ~/remote/vps-srv -p 2222 -o identityFile=~/.ssh/id_ed25519_nopass -o reconnect
end
vpsshu
Unmounts the above.
function vpsshu
fusermount3 -u ~/remote/vps-srv/
end