dotfiles/home/.config/zsh/03-aliases.zsh

270 lines
7.2 KiB
Bash
Raw Normal View History

# git shorthands
alias gc='git commit'
alias gac='ga && gc'
alias gs='git status'
alias gpull='git pull'
alias gpush='git push'
# Rename grc alias from forgit since it
# collides with the grc colorizer
forgit_revert_commit=fgrc
2021-12-18 00:12:45 +02:00
# Modern replacement for ls
2021-08-18 09:30:21 +03:00
alias ls='exa'
{%@@ if profile != "mko-laptop" @@%}
2021-08-17 20:54:45 +03:00
# Command not found handler
# source https://wiki.archlinux.org/title/Zsh#pacman_-F_%22command_not_found%22_handler
function command_not_found_handler {
local purple='\e[1;35m' bright='\e[0;1m' green='\e[1;32m' reset='\e[0m'
printf 'zsh: command not found: %s\n' "$1"
local entries=(
${(f)"$(/usr/bin/pacman -F --machinereadable -- "/usr/bin/$1")"}
)
if (( ${#entries[@]} ))
then
printf "${bright}$1${reset} may be found in the following packages:\n"
local pkg
for entry in "${entries[@]}"
do
# (repo package version file)
local fields=(
${(0)entry}
)
if [[ "$pkg" != "${fields[2]}" ]]
then
printf "${purple}%s/${bright}%s ${green}%s${reset}\n" "${fields[1]}" "${fields[2]}" "${fields[3]}"
fi
printf ' /%s\n' "${fields[4]}"
pkg="${fields[2]}"
done
fi
}
{%@@ endif @@%}
2021-08-17 20:54:45 +03:00
2021-11-13 13:07:50 +02:00
# search and install/remove packages with fzf
2020-11-20 00:23:02 +02:00
pi() {
2021-11-13 13:07:50 +02:00
SELECTED_PKGS="$(paru -Slq | fzf --header='Install packages' -m --preview 'paru -Si {1}')"
if [ -n "$SELECTED_PKGS" ]; then
# Append the expanded command to history
print -s "paru -S $(echo $SELECTED_PKGS)"
2020-11-20 00:23:02 +02:00
paru -S $(echo $SELECTED_PKGS)
fi
}
2020-11-20 00:23:02 +02:00
pr() {
2021-11-13 13:07:50 +02:00
SELECTED_PKGS="$(paru -Qsq | fzf --header='Remove packages' -m --preview 'paru -Si {1}')"
if [ -n "$SELECTED_PKGS" ]; then
# Append the expanded command to history
print -s "paru -Rns $(echo $SELECTED_PKGS)"
2020-11-20 00:23:02 +02:00
paru -Rns $(echo $SELECTED_PKGS)
fi
}
2021-11-13 13:07:50 +02:00
# find and open man pages with fzf
fman() {
2021-11-13 13:07:50 +02:00
man -k . | fzf --prompt='Man> ' | awk '{print $1}' | xargs -r man
}
# I'm retarded so I need this
alias :q='exit'
alias :wq='exit'
2020-03-30 18:21:00 +03:00
alias reboot-kodi='systemctl reboot --boot-loader-entry=kodi.conf'
# zbar output only data
alias zbarimg='zbarimg -q --raw'
alias zbarcam='zbarcam -q --raw'
2020-04-18 13:41:00 +03:00
# shorten systemctl and journalctl
alias sc='systemctl'
alias scu='systemctl --user'
2020-04-18 13:41:00 +03:00
alias jc='journalctl'
alias jcu='journalctl --user'
# switch to desktop mode
alias dock='swaymsg output eDP-1 disable'
# move to trash instead of remove
alias rm='trash'
# clean stuff
clean() {
DFCMD="df -h / | tail -n 1 | cut -d' ' -f8- | cut -d' ' -f1 | sed 's/[^0-9]*//g'"
SPACEBEFORE=$(eval "$DFCMD")
trash-empty 10
sudo journalctl --vacuum-size=500M
2020-11-20 00:23:02 +02:00
paru -Sc
SPACEAFTER=$(eval "$DFCMD")
echo "Saved $(calc $SPACEAFTER - $SPACEBEFORE)G of space"
}
# connect to wireguard
alias startvpn='sudo systemctl start wg-quick@wg0.service'
alias stopvpn='sudo systemctl stop wg-quick@wg0.service'
# read qrcode from selection
qr() { grim -g "$(slurp -d)" - | zbarimg PNG:- }
# generate qr code in terminal
alias qrencode='qrencode -t ansiutf8'
# color picker
cpick() { grim -g "$(slurp -p)" -t ppm - | convert - -format "%[pixel:p{0,0}]" txt:- }
#iwctl aliases
alias i='iwctl station wlan0'
# monitor cpu freq
cpufreq() { watch -n 1 eval "cat /proc/cpuinfo | grep MHz" }
# dotdrop
2022-08-06 12:18:43 +03:00
dotdrop() { source $DOTREPO/secrets/secrets && $DOTREPO/dotdrop/dotdrop.sh --cfg=$DOTREPO/config.toml $@ }
sdotdrop() { source $DOTREPO/secrets/secrets && sudo -E $DOTREPO/dotdrop/dotdrop.sh --cfg=$DOTREPO/config-root.toml $@ }
updatesecrets() { bash $DOTREPO/secrets/secrets.sh; chmod 600 $DOTREPO/secrets/secrets }
compdef _dotdrop-completion.zsh sdotdrop
alias dotgit='git -C $DOTREPO'
dotsync() { cd $DOTREPO && gpull && ga && gc && gpush && cd $OLDPWD }
# sync password manager
passync() { pass git pull && pass git push && updatesecrets }
2020-04-14 14:38:51 +03:00
update() {
all() {
{%@@ if profile == "Moria" or profile == 'Mirkwood' @@%}
2022-04-21 09:09:43 +03:00
paru
{%@@ endif @@%}
{%@@ if profile == "mko-laptop" @@%}
apt
{%@@ endif @@%}
2020-04-14 14:38:51 +03:00
{%@@ if profile == "Moria" @@%}
2020-12-25 10:59:03 +02:00
repo
2020-04-15 13:09:11 +03:00
docker-update
2020-04-14 14:38:51 +03:00
{%@@ endif @@%}
2022-03-05 08:38:19 +02:00
plugins
2020-04-14 14:38:51 +03:00
}
plugins() {
2022-08-05 09:37:38 +03:00
nvim -c 'autocmd User PackerComplete quitall' -c 'PackerSync'
2020-04-14 14:38:51 +03:00
zinit self-update
zinit update -p
$HOME/.tmux/plugins/tpm/bin/update_plugins all
}
2022-08-03 09:47:44 +03:00
{%@@ if profile == "Moria" @@%}
repo() {
aur sync -Su --margs --noconfirm
}
2020-04-15 13:09:11 +03:00
docker-update() {
2020-11-21 15:37:58 +02:00
for dir in $HOME/git/dotfiles/docker/*; do
2020-04-14 14:38:51 +03:00
cd $dir
if [[ -f "DISABLED" ]]; then
2022-04-11 15:52:25 +03:00
echo "$(basename $dir) stack is disabled, skipping..."
else
dct pull
dct up -d
fi
2022-04-21 09:09:43 +03:00
cd ..
2020-04-14 14:38:51 +03:00
done
docker system prune -af --volumes
2020-04-14 14:38:51 +03:00
}
2022-08-03 09:47:44 +03:00
{%@@ endif @@%}
{%@@ if profile == "mko-laptop" @@%}
apt-upd() {
sudo apt update && sudo apt full-upgrade -y && sudo apt autoremove -y && sudo apt autoclean -y
}
2022-08-03 09:47:44 +03:00
{%@@ endif @@%}
2020-04-14 14:03:21 +03:00
2020-04-14 14:38:51 +03:00
case "$1" in
all)
all
;;
plugins)
plugins
;;
{%@@ if profile == "Moria" @@%}
2020-04-14 14:38:51 +03:00
docker)
2020-04-15 13:09:11 +03:00
docker-update
2020-04-14 14:38:51 +03:00
;;
2020-12-25 11:11:53 +02:00
repo)
repo
;;
{%@@ endif @@%}
{%@@ if profile == "mko-laptop" @@%}
apt)
2022-08-03 09:47:44 +03:00
apt-upd
;;
{%@@ endif @@%}
2020-04-14 14:38:51 +03:00
*)
2022-08-03 09:47:44 +03:00
{%@@ if profile == "mko-laptop" @@%}
apt-upd
2020-04-14 14:38:51 +03:00
;;
2022-08-03 09:47:44 +03:00
{%@@ else @@%}
paru
;;
{%@@ endif @@%}
2020-04-14 14:38:51 +03:00
esac
2020-04-14 14:03:21 +03:00
}
# turn on usb tethering on my android phone
tether() { adb shell su -c "service call connectivity 33 i32 1 s16 me" > /dev/null }
# update arch mirrorlist
alias reflect='sudo reflector --latest 200 --threads 8 --verbose --protocol http --protocol https --sort rate --save /etc/pacman.d/mirrorlist'
# default icon for notify-send
alias notify-send='notify-send --icon=alarm'
2020-03-03 16:54:32 +02:00
# download archiso
alias archiso='curl "http://mirror.rackspace.com/archlinux/iso/$(date +%Y.%m).01/archlinux-$(date +%Y.%m).01-x86_64.iso"'
# encrypted tar's with zstd compression
cgpgtar() { tar cf - --zstd $1 | gpg -e -z 0 > $1.tar.zst.gpg }
xgpgtar() { gpg -d $1 | tar x --zstd }
2022-03-29 23:00:50 +03:00
# Switch to different yubikey
2022-03-29 23:02:07 +03:00
alias switch-yubikey='gpg-connect-agent "scd serialno" "learn --force" /bye'
2022-03-29 23:00:50 +03:00
2020-04-27 13:22:08 +03:00
btw, () {
echo " I use"
echo " ▄
▟█▙
▟███▙
▟█████▙
▟███████▙
▂▔▀▜██████▙
▟██▅▂▝▜█████▙
▟█████████████▙
▟███████████████▙
▟█████████████████▙
▟███████████████████▙
▟█████████▛▀▀▜████████▙
▟████████▛ ▜███████▙
▟█████████ ████████▙
▟██████████ █████▆▅▄▃▂
▟██████████▛ ▜█████████▙
▟██████▀▀▀ ▀▀██████▙
▟███▀▘ ▝▀███▙
▟▛▀ ▀▜▙"
}
2022-02-26 13:18:03 +02:00
# docker-compose with TOML
dct() {
local file_path=('./docker-compose.toml')
zmodload zsh/zutil
zparseopts -D -K -- \
f:=file_path ||
return 1
file_path=${file_path[-1]}
if [[ ! -a "$file_path" ]]; then
echo "File $file_path does not exist!"
return 1
fi
yj -ty < $file_path | docker-compose -f - $@
}