From 7df9df3e296451a1cd9e311bb81e737efe9882fd Mon Sep 17 00:00:00 2001 From: Phil Bajsicki Date: Sat, 15 Apr 2023 17:20:42 +0200 Subject: [PATCH] Add fish --- .config/fish/config.fish | 356 +++++++++++++++++++++ .config/fish/fish_variables | 27 ++ .config/fish/functions/colemak.fish | 3 + .config/fish/functions/emacs.fish | 3 + .config/fish/functions/phil-fix-names.fish | 3 + .config/fish/functions/polish.fish | 3 + .config/fish/functions/vps.fish | 3 + .config/fish/functions/vpssh.fish | 3 + .config/fish/functions/vpsshu.fish | 3 + .config/fish/functions/xfce4-notifyd.fish | 3 + 10 files changed, 407 insertions(+) create mode 100755 .config/fish/config.fish create mode 100644 .config/fish/fish_variables create mode 100644 .config/fish/functions/colemak.fish create mode 100644 .config/fish/functions/emacs.fish create mode 100644 .config/fish/functions/phil-fix-names.fish create mode 100644 .config/fish/functions/polish.fish create mode 100644 .config/fish/functions/vps.fish create mode 100644 .config/fish/functions/vpssh.fish create mode 100644 .config/fish/functions/vpsshu.fish create mode 100644 .config/fish/functions/xfce4-notifyd.fish diff --git a/.config/fish/config.fish b/.config/fish/config.fish new file mode 100755 index 0000000..2df69a9 --- /dev/null +++ b/.config/fish/config.fish @@ -0,0 +1,356 @@ +# ____ _____ +# | _ \_ _| Derek Taylor (DistroTube) +# | | | || | http://www.youtube.com/c/DistroTube +# | |_| || | http://www.gitlab.com/dwt1/ +# |____/ |_| +# +# My fish config. Not much to see here; just some pretty standard stuff. + +### ADDING TO THE 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/.local/bin $HOME/Applications $HOME/.cabal/bin $HOME/.ghcup/bin $fish_user_paths + + +### EXPORT ### +set fish_greeting # Supresses fish's intro message +set TERM "xterm-256color" # Sets the terminal type +set EDITOR "emacsclient -t -a ''" # $EDITOR use Emacs in terminal +set VISUAL "emacsclient -c -a emacs" # $VISUAL use Emacs in GUI mode +# set QT_QPA_PLATFORMTHEME "qt5ct" + + +### SET MANPAGER +### Uncomment only one of these! + +### "bat" as manpager +set -x MANPAGER "sh -c 'col -bx | bat -l man -p'" + +### "vim" as manpager +# 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 OF SPARK ### + + +### FUNCTIONS ### +# 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 + +# Functions needed 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 +# The 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 + +# Function for creating a backup file +# ex: backup file.txt +# result: copies file as file.txt.bak +function backup --argument filename + cp $filename $filename.bak +end + +# Function for copying files and directories, even recursively. +# ex: copy DIRNAME LOCATIONS +# result: copies the directory and all of its contents. +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 + +# Function for printing a column (splits input on whitespace) +# ex: echo 1 2 3 | coln 3 +# output: 3 +function coln + while read -l input + echo $input | awk '{print $'$argv[1]'}' + end +end + +# Function for printing a row +# ex: seq 3 | rown 3 +# output: 3 +function rown --argument index + sed -n "$index p" +end + +# Function for ignoring the first 'n' lines +# ex: seq 10 | skip 5 +# results: prints everything but the first 5 lines +function skip --argument n + tail +(math 1 + $n) +end + +# Function for taking the first 'n' lines +# ex: seq 10 | take 5 +# results: prints only the first 5 lines +function take --argument number + head -$number +end + +# Function for org-agenda +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 OF FUNCTIONS ### + + +### ALIASES ### +alias clear='/bin/clear; echo; echo; seq 1 (tput cols) | sort -R | spark | lolcat; echo; echo' + +# root privileges +alias doas="doas --" + +# navigation +alias ..='cd ..' +alias ...='cd ../..' +alias .3='cd ../../..' +alias .4='cd ../../../..' +alias .5='cd ../../../../..' + +# vim and emacs +alias vim='nvim' +alias em='/usr/bin/emacs -nw' +alias emacs="emacsclient -c -a 'emacs'" +alias doomsync="~/.emacs.d/bin/doom sync" +alias doomdoctor="~/.emacs.d/bin/doom doctor" +alias doomupgrade="~/.emacs.d/bin/doom upgrade" +alias doompurge="~/.emacs.d/bin/doom purge" + +# Changing "ls" to "exa" +alias ls='exa -al --color=always --group-directories-first' # my preferred listing +alias la='exa -a --color=always --group-directories-first' # all files and dirs +alias ll='exa -l --color=always --group-directories-first' # long format +alias lt='exa -aT --color=always --group-directories-first' # tree listing +alias l.='exa -a | egrep "^\."' + +# pacman and yay +alias pacsyu='sudo pacman -Syyu' # update only standard pkgs +alias yaysua='yay -Sua --noconfirm' # update only AUR pkgs (yay) +alias yaysyu='yay -Syu --noconfirm' # update standard pkgs and AUR pkgs (yay) +alias parsua='paru -Sua --noconfirm' # update only AUR pkgs (paru) +alias parsyu='paru -Syu --noconfirm' # update standard pkgs and AUR pkgs (paru) +alias unlock='sudo rm /var/lib/pacman/db.lck' # remove pacman lock +alias cleanup='sudo pacman -Rns (pacman -Qtdq)' # remove orphaned packages + +# get fastest mirrors +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" + +# Colorize grep output (good for log files) +alias grep='grep --color=auto' +alias egrep='egrep --color=auto' +alias fgrep='fgrep --color=auto' + +# confirm before overwriting something +alias cp="cp -i" +alias mv='mv -i' +alias rm='rm -i' + +# adding flags +alias df='df -h' # human-readable sizes +alias free='free -m' # show sizes in MB +alias lynx='lynx -cfg=~/.lynx/lynx.cfg -lss=~/.lynx/lynx.lss -vikeys' +alias vifm='./.config/vifm/scripts/vifmrun' +alias ncmpcpp='ncmpcpp ncmpcpp_directory=$HOME/.config/ncmpcpp/' +alias mocp='mocp -M "$XDG_CONFIG_HOME"/moc -O MOCDir="$XDG_CONFIG_HOME"/moc' + +# 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 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' + +# get error messages from journalctl +alias jctl="journalctl -p 3 -xb" + +# gpg encryption +# verify signature for isos +alias gpg-check="gpg2 --keyserver-options auto-key-retrieve --verify" +# receive the key of a developer +alias gpg-retrieve="gpg2 --keyserver-options auto-key-retrieve --receive-keys" + +# youtube-dl +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 " + +# switch between shells +# I do not recommend switching default SHELL from bash. +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.'" + +# bare git repo alias for dotfiles +alias config="/usr/bin/git --git-dir=$HOME/git/dot --work-tree=$HOME" + +# termbin +alias tb="nc termbin.com 9999" + +# the terminal rickroll +alias rr='curl -s -L https://raw.githubusercontent.com/keroserene/rickrollrc/master/roll.sh | bash' + +# Unlock LBRY tips +alias tips="lbrynet txo spend --type=support --is_not_my_input --blocking" + +### DTOS ### +# Copy/paste all content of /etc/dtos over to home folder. A backup of config is created. (Be careful running this!) +alias dtoscopy='[ -d ~/.config ] || mkdir ~/.config && cp -Rf ~/.config ~/.config-backup-(date +%Y.%m.%d-%H.%M.%S) && cp -rf /etc/dtos/* ~' +# Backup contents of /etc/dtos to a backup folder in $HOME. +alias dtosbackup='cp -Rf /etc/dtos ~/dtos-backup-(date +%Y.%m.%d-%H.%M.%S)' + +### RANDOM COLOR SCRIPT ### +# Get this script from my GitLab: gitlab.com/dwt1/shell-color-scripts +# Or install it from the Arch User Repository: shell-color-scripts +colorscript random + +### SETTING THE STARSHIP PROMPT ### +starship init fish | source + +### ENVIRONMENT VARIABLES ### +set -gx PATH "$HOME/.cabal/bin:$HOME/.ghcup/bin:$PATH" + +# >>> conda initialize >>> +# !! Contents within this block are managed by 'conda init' !! +if test -f /home/phil/tech/Apps/miniconda3/bin/conda + eval /home/phil/tech/Apps/miniconda3/bin/conda "shell.fish" "hook" $argv | source +end +# <<< conda initialize <<< + diff --git a/.config/fish/fish_variables b/.config/fish/fish_variables new file mode 100644 index 0000000..9142a66 --- /dev/null +++ b/.config/fish/fish_variables @@ -0,0 +1,27 @@ +# This file contains fish universal variable definitions. +# VERSION: 3.0 +SETUVAR __fish_initialized:3400 +SETUVAR fish_color_cancel:\x2dr +SETUVAR fish_color_comment:red +SETUVAR fish_color_cwd:green +SETUVAR fish_color_cwd_root:red +SETUVAR fish_color_end:green +SETUVAR fish_color_escape:brcyan +SETUVAR fish_color_history_current:\x2d\x2dbold +SETUVAR fish_color_host:normal +SETUVAR fish_color_host_remote:yellow +SETUVAR fish_color_operator:brcyan +SETUVAR fish_color_quote:yellow +SETUVAR fish_color_redirection:cyan\x1e\x2d\x2dbold +SETUVAR fish_color_search_match:\x2d\x2dbackground\x3d111 +SETUVAR fish_color_selection:white\x1e\x2d\x2dbold\x1e\x2d\x2dbackground\x3dbrblack +SETUVAR fish_color_status:red +SETUVAR fish_color_user:brgreen +SETUVAR fish_color_valid_path:\x2d\x2dunderline +SETUVAR fish_key_bindings:fish_vi_key_bindings +SETUVAR fish_pager_color_completion:normal +SETUVAR fish_pager_color_description:B3A06D\x1eyellow\x1e\x2di +SETUVAR fish_pager_color_prefix:cyan\x1e\x2d\x2dbold\x1e\x2d\x2dunderline +SETUVAR fish_pager_color_progress:brwhite\x1e\x2d\x2dbackground\x3dcyan +SETUVAR fish_pager_color_selected_background:\x2dr +SETUVAR fish_user_paths:/home/phil/\x2elocal/bin\x1e/home/phil/Applications\x1e/home/phil/\x2ecabal/bin\x1e/home/phil/\x2eghcup/bin diff --git a/.config/fish/functions/colemak.fish b/.config/fish/functions/colemak.fish new file mode 100644 index 0000000..a9c5804 --- /dev/null +++ b/.config/fish/functions/colemak.fish @@ -0,0 +1,3 @@ +function colemak --wraps=setxkbmap\ -model\ \'pc104angle-z\'\ -layout\ \'us\(cmk_ed_us\)\'\ -option\ \'misc:extend,lv5:caps_switch_lock,misc:cmk_curl_dh\' --description alias\ colemak=setxkbmap\ -model\ \'pc104angle-z\'\ -layout\ \'us\(cmk_ed_us\)\'\ -option\ \'misc:extend,lv5:caps_switch_lock,misc:cmk_curl_dh\' + setxkbmap -model 'pc104angle-z' -layout 'us(cmk_ed_us)' -option 'misc:extend,lv5:caps_switch_lock,misc:cmk_curl_dh' $argv; +end diff --git a/.config/fish/functions/emacs.fish b/.config/fish/functions/emacs.fish new file mode 100644 index 0000000..ddc0e6a --- /dev/null +++ b/.config/fish/functions/emacs.fish @@ -0,0 +1,3 @@ +function emacs --wraps=emacsclient\ -c\ -a\ \'emacs\' --description 'alias emacs emacs' + command emacs $argv; +end diff --git a/.config/fish/functions/phil-fix-names.fish b/.config/fish/functions/phil-fix-names.fish new file mode 100644 index 0000000..5d53d98 --- /dev/null +++ b/.config/fish/functions/phil-fix-names.fish @@ -0,0 +1,3 @@ +function phil-fix-names --wraps=perl-rename\ \'y/A-Z/a-z/\'\ \*\ \&\&\ perl-rename\ \'y/\ /-/\'\ \* --description alias\ phil-fix-names\ perl-rename\ \'y/A-Z/a-z/\'\ \*\ \&\&\ perl-rename\ \'y/\ /-/\'\ \* + perl-rename 'y/A-Z/a-z/' * && perl-rename 'y/ /-/' * $argv; +end diff --git a/.config/fish/functions/polish.fish b/.config/fish/functions/polish.fish new file mode 100644 index 0000000..3fa54ca --- /dev/null +++ b/.config/fish/functions/polish.fish @@ -0,0 +1,3 @@ +function polish --wraps='setxkbmap -model pc104 -layout pl' --wraps='setxkbmap -model pc104 -layout pl -options compose:rctrl' --wraps='setxkbmap -model pc104 -layout pl -option compose:rctrl' --description 'alias polish=setxkbmap -model pc104 -layout pl -option compose:rctrl' + setxkbmap -model pc104 -layout pl -option compose:rctrl $argv; +end diff --git a/.config/fish/functions/vps.fish b/.config/fish/functions/vps.fish new file mode 100644 index 0000000..d5455b4 --- /dev/null +++ b/.config/fish/functions/vps.fish @@ -0,0 +1,3 @@ +function vps --wraps='ssh -p 2222 phil@46.38.232.163 -i .ssh/id_ed25519_nopass' --wraps='ssh -p 22 phil@46.38.232.163 -i .ssh/id_ed25519_nopass' --description 'alias vps ssh -p 2222 phil@46.38.232.163 -i .ssh/id_ed25519_nopass' + ssh -p 2222 phil@46.38.232.163 -i .ssh/id_ed25519_nopass $argv; +end diff --git a/.config/fish/functions/vpssh.fish b/.config/fish/functions/vpssh.fish new file mode 100644 index 0000000..d6cf9a1 --- /dev/null +++ b/.config/fish/functions/vpssh.fish @@ -0,0 +1,3 @@ +function vpssh --wraps='sshfs phil@46.38.232.163:/srv/ vps-srv -p 2222 -o identityFile=~/.ssh/id_ed25519_nopass -o reconnect' --wraps='sshfs phil@46.38.232.163:/srv/ ~/remote/vps-srv -p 22 -o identityFile=~/.ssh/id_ed25519_nopass -o reconnect' --wraps='sshfs phil@46.38.232.163:/srv/ ~/remote/vps-srv -p 2222 -o identityFile=~/.ssh/id_ed25519_nopass -o reconnect' --description 'alias vpssh sshfs phil@46.38.232.163:/srv/ ~/remote/vps-srv -p 2222 -o identityFile=~/.ssh/id_ed25519_nopass -o reconnect' + sshfs phil@46.38.232.163:/srv/ ~/remote/vps-srv -p 2222 -o identityFile=~/.ssh/id_ed25519_nopass -o reconnect $argv; +end diff --git a/.config/fish/functions/vpsshu.fish b/.config/fish/functions/vpsshu.fish new file mode 100644 index 0000000..9d9a5fa --- /dev/null +++ b/.config/fish/functions/vpsshu.fish @@ -0,0 +1,3 @@ +function vpsshu --wraps='fusermount3 -u ~/remote/vps-srv/' --description 'alias vpsshu fusermount3 -u ~/remote/vps-srv/' + fusermount3 -u ~/remote/vps-srv/ $argv; +end diff --git a/.config/fish/functions/xfce4-notifyd.fish b/.config/fish/functions/xfce4-notifyd.fish new file mode 100644 index 0000000..af4b935 --- /dev/null +++ b/.config/fish/functions/xfce4-notifyd.fish @@ -0,0 +1,3 @@ +function xfce4-notifyd --wraps=/usr/lib/xfce4/notifyd/xfce4-notifyd --description 'alias xfce4-notifyd /usr/lib/xfce4/notifyd/xfce4-notifyd' + /usr/lib/xfce4/notifyd/xfce4-notifyd $argv; +end