profile/aliases.sh
2026-10-27 13:13:37 +00:00

79 lines
1.7 KiB
Bash

#!/bin/sh
# Common interactive aliases and helpers using POSIX shell syntax.
alias venv='. ./venv/bin/activate'
alias e='nvim'
alias er='nvim README.md'
alias et='nvim TODO.md'
alias en='nvim NOTES.md'
alias ens='nvim NEXT_STEPS.md'
alias ea='nvim .autonote.md'
alias ee='nvim .'
debuglog() {
clear
: > debug.log
tail -f debug.log
}
alias g='git status'
gg() {
_gg_message=${*:-update}
if git add . && git commit -m "$_gg_message" && git push; then
unset _gg_message
return 0
fi
unset _gg_message
return 1
}
wget() {
printf 'wget wrapper: using HSTS file %s\n' "$XDG_DATA_HOME/wget-hsts" >&2
command wget --hsts-file="$XDG_DATA_HOME/wget-hsts" "$@"
}
alias bc='bc -q -l'
alias ytdl='yt-dlp --write-info-json --write-description --no-playlist'
alias ytdlb='yt-dlp --write-info-json --write-description --no-playlist -a'
alias ytdl-mp3='yt-dlp -f bestaudio --extract-audio --audio-format mp3 --embed-thumbnail --add-metadata'
# lf gets confused by TERMINFO when running in tmux.
# https://github.com/gokcehan/lf/issues/138#issuecomment-464477665
if [ -n "${TERMINFO:-}" ]; then
alias lf='TERMINFO= lf -last-dir-path="$HOME/.cache/lf-last-dir"'
else
alias lf='lf -last-dir-path="$HOME/.cache/lf-last-dir"'
fi
cdlf() {
[ -r "$HOME/.cache/lf-last-dir" ] || return 1
IFS= read -r _cdlf_last_dir < "$HOME/.cache/lf-last-dir"
[ -n "$_cdlf_last_dir" ] || return 1
if cd "$_cdlf_last_dir"; then
unset _cdlf_last_dir
return 0
fi
unset _cdlf_last_dir
return 1
}
lfcd() {
lf -last-dir-path="$HOME/.cache/lf-last-dir" && cdlf
}
mkcd() {
if [ "$#" -ne 1 ]; then
printf '%s\n' 'Usage: mkcd <directory>' >&2
return 2
fi
mkdir -p "$1" || return
cd "$1" || return
}