Files
dotfiles/zsh/aliases.zsh
2026-08-17 21:02:43 +02:00

63 lines
1.4 KiB
Bash

#!/usr/bin/false
# LC_COLLATE=C: sort case-sensitive, i.e. README before aaa.py
alias ls='LC_COLLATE=C ls --color --group-directories-first'
alias ll='LC_COLLATE=C ls -la'
alias la='LC_COLLATE=C ls -A'
alias l='LC_COLLATE=C ls -CF'
alias xo='xdg-open'
alias pacman="sudo pacman"
alias history="history 0" # force zsh to show the complete history
# create directory and set it as cwd
alias take=_take
_take() {
if [ -z "$1" ]; then
printf 'usage: %s directory' $0 > /dev/stderr
return 1
fi
mkdir -p $1
cd $1
}
# gd: Check dependencies and auth
_gdcheck() {
# deps
local missing=()
for cmd in rclone zstd gpg; do
command -v "$cmd" >/dev/null 2>&1 || missing+=("$cmd")
done
(( ${#missing[@]} == 0 )) || {
print -u2 "Missing dependencies: ${missing[*]}"
return 1
}
# auth
rclone lsd gdrive: >/dev/null 2>&1 || {
print -u2 "Google Drive auth failed; try: rclone config reconnect gdrive:"
return 1
}
}
# gdpush pushes a file to Google Drive
gdpush() {
_gdcheck || return
zstd -6 -T0 -c -- "$1" | gpg -c -z 0 -o - | rclone rcat "gdrive:backups/${1:t}.zst.gpg"
}
# gdls lists files in Google Drive
gdls() {
_gdcheck || return
rclone lsf --files-only gdrive:backups/ | sed 's/\.zst\.gpg$//'
}
# gdpull pulls a file from Google Drive
gdpull() {
_gdcheck || return
rclone cat "gdrive:backups/${1:t}.zst.gpg" | gpg -d | zstd -d -c
}