Files
dotfiles/.config/shell/aliasrc

247 lines
6.8 KiB
Plaintext
Raw Normal View History

2021-04-07 22:56:28 +01:00
#!/bin/sh
# Use neovim for vim if present
[ -x "$(command -v nvim)" ] && alias vim="nvim" vimdiff="nvim -d"
# Use $XINITRC variable if file exists.
[ -f "$XINITRC" ] && alias startx="startx $XINITRC"
2024-01-21 17:42:05 +00:00
# sudo not required for some system commands
2021-04-07 22:56:28 +01:00
for x in mount umount sv pacman updatedb su ; do
2024-01-21 17:42:05 +00:00
alias $x="sudo $x"
2021-04-07 22:56:28 +01:00
done
# Verbosity and settings that you pretty much just always are going to want.
alias \
cp="cp -iv" \
mv="mv -iv" \
rm="rm -vI" \
bc="bc -ql" \
mkd="mkdir -pv" \
yt="youtube-dl --add-metadata -i" \
yta="yt -x -f bestaudio/best" \
ffmpeg="ffmpeg -hide_banner" \
2025-06-20 22:19:09 +01:00
tmux="tmux -f ~/.config/tmux/tmux.conf" \
aider="aider --config ~/.config/aider/aider.yaml"
2021-04-07 22:56:28 +01:00
# Colorize commands when possible.
alias \
2025-02-22 22:20:15 +00:00
ls="ls -hAN --color=auto --group-directories-first"\
li="ls -AhgGFt --group-directories-first --time=atime --color=auto --time-style=long-iso \
| sed 's/^[^ ][^ ]* *[^ ][^ ]* //' \
| awk '\
/^total/ { next }\
{\
filename = \$NF;\
icon = \"📄\";\
if (filename ~ /\/$/) {\
icon = \"📁\";\
} else if (filename ~ /\*$/) {\
icon = \"⚙️ \";\
} else if (filename ~ /@$/) {\
icon = \"🔗\";\
} else {\
ext = tolower(cleanName);\
if (ext ~ /\./) {\
sub(/^.*\./, \"\", ext);\
} else {\
ext = \"\";\
}\
if (ext ~ /^(jpg|jpeg|png|gif)$/) {\
icon = \"🖼\";\
} else if (ext ~ /^(mp3|wav|flac)$/) {\
icon = \"🎵\";\
} else if (ext ~ /^(pdf)$/) {\
icon = \"📕\";\
} else if (ext ~ /^(txt|md)$/) {\
icon = \"📝\";\
} else if (ext ~ /^(js|py|sh|c|cpp|java)$/) {\
icon = \"⚡\";\
}\
}\
print icon \" \" \$0;\
}\
'" \
2021-04-07 22:56:28 +01:00
grep="grep --color=auto" \
diff="diff --color=auto" \
ccat="highlight --out-format=ansi"
# Abbreviating long commands
alias \
ka="killall" \
YT="youtube-viewer" \
2024-01-21 17:42:05 +00:00
sdn="sudo shutdown -h now" \
2021-04-07 22:56:28 +01:00
e="$EDITOR" \
v="$EDITOR" \
2021-04-16 00:29:01 +01:00
cl="clear" \
2024-01-21 17:42:05 +00:00
p="sudo pacman" \
2021-04-07 22:56:28 +01:00
z="zathura" \
2025-02-22 22:20:15 +00:00
ll="ls -AhlFt --group-directories-first --time=atime --color=auto --time-style=long-iso" \
2021-04-09 20:36:10 +01:00
ag="alias | grep" \
2021-05-01 15:08:04 +01:00
lc="clone_from_labs" \
gc="clone_from_github" \
2021-07-16 16:54:09 +01:00
dgit="git --git-dir ~/.config/dotfiles/.git --work-tree=$HOME" \
2021-10-02 20:02:17 +01:00
.z="source ~/.config/shell/profile" \
2025-02-22 22:20:15 +00:00
.a="source ~/.config/shell/aliasrc" \
2025-06-20 22:19:09 +01:00
testmic="arecord -vv -f dat /dev/null" \
notes="cd ~/Tower/Notes && nvim ." \
aid="aider"
2021-04-07 22:56:28 +01:00
2025-11-03 22:20:56 +00:00
# Projects
alias \
src="tmuxinator start runcats"
2023-10-18 21:10:32 +01:00
# Dev
alias \
2025-08-03 11:01:51 +01:00
sail='[ -f sail ] && sh sail || sh vendor/bin/sail' \
yi="yarn install" \
2025-11-12 09:28:25 +00:00
y="yarn" \
2025-08-03 11:01:51 +01:00
ci="composer install" \
2025-11-12 09:28:25 +00:00
c="composer" \
2025-11-03 22:20:56 +00:00
tk="go-task" \
mux="tmuxinator" \
2025-11-07 14:28:09 +00:00
mex="tmuxinator stop-all" \
lg="lazygit"
2023-10-18 21:10:32 +01:00
2021-11-07 18:21:10 +00:00
# Translating
alias \
ro="trans ro:en -j -- " \
2021-11-21 18:23:28 +00:00
roi="trans ro:en -i" \
2021-11-28 17:49:25 +00:00
enr="trans en:ro -j -- " \
enri="trans en:ro -i"
2021-11-07 18:21:10 +00:00
2025-08-13 09:07:22 +01:00
function tf() {
php artisan test --filter="$*"
}
2025-02-22 22:20:15 +00:00
function cdj() {
dir=$1
cd $1 2>/dev/null || autojump $1
}
function dut() {
threshold=${1:-5}
sudo du -hax -t"${threshold}G" /* --exclude=/{proc,sys,dev,run}
}
function gh() {
local -a commands=(
2025-06-20 22:19:09 +01:00
"Recover deleted file: git checkout HEAD -- <file>"
2025-02-22 22:20:15 +00:00
"Revert previous commit keeping changes: git revert --no-commit HEAD~1"
"Undo merge/pull that caused conflicts: git revert -m 1 HEAD~1"
"Abort rebase: git rebase --abort"
"Unstage a file: git restore --staged <file>"
"Undo a pushed commit: git reset --hard HEAD~1 && git push --force"
)
echo "Git First-Aid:"
echo "--------------------------------"
2025-11-03 22:20:56 +00:00
2025-02-22 22:20:15 +00:00
for i in {1..${#commands[@]}}; do
echo "$i) ${commands[$i]}"
done
echo "--------------------------------"
}
2021-05-01 15:08:04 +01:00
# Clone from labs
2025-02-22 22:20:15 +00:00
function cll() {
2021-05-01 15:08:04 +01:00
git clone "git@labs.scarif.space:chris/$1" "${@:2}"
}
# Clone from github
2025-02-22 22:20:15 +00:00
function clg() {
2021-05-01 15:08:04 +01:00
git clone "https://github.com/$1" "${@:2}"
}
2025-04-10 17:17:27 +01:00
function lp() {
lsof -i -P -n $@ | grep LISTEN
}
2021-04-16 00:06:15 +01:00
# Check if main exists and use instead of master
function git_main_branch() {
command git rev-parse --git-dir &>/dev/null || return
local branch
for branch in main trunk; do
if command git show-ref -q --verify refs/heads/$branch; then
echo $branch
return
fi
done
echo master
}
2025-11-11 22:03:07 +00:00
# Yazi shortcut that allows setting the current working directory on exit
2025-11-12 09:28:25 +00:00
function yz() {
2025-11-11 22:03:07 +00:00
local tmp="$(mktemp -t "yazi-cwd.XXXXXX")" cwd
yazi "$@" --cwd-file="$tmp"
IFS= read -r -d '' cwd < "$tmp"
[ -n "$cwd" ] && [ "$cwd" != "$PWD" ] && builtin cd -- "$cwd"
rm -f -- "$tmp"
}
2021-04-07 22:56:28 +01:00
# Git aliases
alias \
g="git" \
ga="git add" \
2021-09-07 21:50:15 +01:00
dga="dgit add -f" \
2021-10-05 21:54:44 +01:00
dgc="dgit commit" \
2021-09-07 21:50:15 +01:00
dgcm="dgit commit -m" \
dgs="dgit status" \
dgd="dgit diff" \
dgdc="dgit diff --cached" \
2021-09-09 22:28:27 +01:00
dgp="dgit push" \
dgup="dgit pull --rebase" \
2021-09-07 21:50:15 +01:00
gaa="git add --all" \
2021-04-07 22:56:28 +01:00
gb="git branch" \
gba="git branch -a" \
gbd="git branch -d" \
gbD="git branch -D" \
gbs="git bisect" \
gbsb="git bisect bad" \
gbsg="git bisect good" \
gbsr="git bisect reset" \
gbss="git bisect start" \
gc="git commit -v" \
gc!="git commit -v --amend" \
gcn!="git commit -v --no-edit --amend" \
gca="git commit -v -a" \
gca!="git commit -v -a --amend" \
gcan!="git commit -v -a --no-edit --amend" \
gcam="git commit -a -m" \
2021-09-30 22:46:23 +01:00
gcmsg="git commit -m" \
2021-04-07 22:56:28 +01:00
gcm="git checkout $(git_main_branch)" \
gco="git checkout" \
gcb="git checkout -b" \
gf="git fetch" \
gfa="git fetch --all --prune" \
gd="git diff" \
2021-09-07 21:50:15 +01:00
gdc="git diff --cached" \
2025-08-06 21:34:13 +01:00
gl="git pull --no-rebase" \
2021-04-07 22:56:28 +01:00
glg="git log --stat" \
glgg="git log --graph" \
glo="git log --oneline --decorate" \
glgp="git log --stat -p" \
gm="git merge" \
gp="git push" \
grb="git rebase" \
2025-08-23 12:17:17 +01:00
grba="git rebase --abort" \
grbc="git rebase --continue" \
2021-04-07 22:56:28 +01:00
gsb="git status -sb" \
gsh="git show" \
gsps="git show --pretty=short --show-signature" \
gsta="git stash push" \
gstaa="git stash apply" \
gstp="git stash pop" \
gstl="git stash list" \
gsts="git stash show --text" \
gup="git pull --rebase" \
nah="git reset --hard; git clean -df" \
gapa="git add --patch -A" \
gun="git reset --" \
glgm="git log --stat --author=christopher" \
glgpm="git log --stat -p --author=christopher"