Adding aliases and stuff
This commit is contained in:
@@ -26,7 +26,42 @@ alias \
|
||||
|
||||
# Colorize commands when possible.
|
||||
alias \
|
||||
ls="ls -hN --color=auto --group-directories-first" \
|
||||
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;\
|
||||
}\
|
||||
'" \
|
||||
grep="grep --color=auto" \
|
||||
diff="diff --color=auto" \
|
||||
ccat="highlight --out-format=ansi"
|
||||
@@ -41,18 +76,22 @@ alias \
|
||||
cl="clear" \
|
||||
p="sudo pacman" \
|
||||
z="zathura" \
|
||||
ll="ls -l" \
|
||||
la="ls -al" \
|
||||
ll="ls -AhlFt --group-directories-first --time=atime --color=auto --time-style=long-iso" \
|
||||
ag="alias | grep" \
|
||||
lc="clone_from_labs" \
|
||||
gc="clone_from_github" \
|
||||
dgit="git --git-dir ~/.config/dotfiles/.git --work-tree=$HOME" \
|
||||
.z="source ~/.config/shell/profile" \
|
||||
.a="source ~/.config/shell/aliasrc" \
|
||||
testmic="arecord -vv -f dat /dev/null"
|
||||
|
||||
# Dev
|
||||
alias \
|
||||
sail='[ -f sail ] && sh sail || sh vendor/bin/sail'
|
||||
yi="yarn install"
|
||||
y="yarn"
|
||||
ci="composer install"
|
||||
c="composer"
|
||||
|
||||
# Translating
|
||||
alias \
|
||||
@@ -61,13 +100,43 @@ alias \
|
||||
enr="trans en:ro -j -- " \
|
||||
enri="trans en:ro -i"
|
||||
|
||||
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=(
|
||||
"Recover deleted file: git checkout HEAD~1 -- <file>"
|
||||
"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 "--------------------------------"
|
||||
|
||||
for i in {1..${#commands[@]}}; do
|
||||
echo "$i) ${commands[$i]}"
|
||||
done
|
||||
|
||||
echo "--------------------------------"
|
||||
}
|
||||
|
||||
# Clone from labs
|
||||
function clone_from_labs() {
|
||||
function cll() {
|
||||
git clone "git@labs.scarif.space:chris/$1" "${@:2}"
|
||||
}
|
||||
|
||||
# Clone from github
|
||||
function clone_from_github() {
|
||||
function clg() {
|
||||
git clone "https://github.com/$1" "${@:2}"
|
||||
}
|
||||
|
||||
|
||||
@@ -99,17 +99,53 @@ preexec() {
|
||||
echo -ne '\e[5 q'
|
||||
}
|
||||
|
||||
# Use lf to switch directories and bind it to ctrl-o
|
||||
lfcd() {
|
||||
tmp="$(mktemp)"
|
||||
lf -last-dir-path="$tmp" "$@"
|
||||
if [ -f "$tmp" ]; then
|
||||
dir="$(cat "$tmp")"
|
||||
rm -f "$tmp" >/dev/null
|
||||
[ -d "$dir" ] && [ "$dir" != "$(pwd)" ] && cd "$dir"
|
||||
function alias_suggestion_check() {
|
||||
local current_cmd="$1"
|
||||
|
||||
if [[ -z "$current_cmd" || ${#current_cmd} -lt 7 ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
local recent_count="$(history 500 | grep -c -E "^[0-9 ]+${current_cmd}")"
|
||||
if [[ $recent_count -ge 3 ]]; then
|
||||
echo "\033[33m[ALIAS SUGGESTION]: You've run '$current_cmd' multiple times. Consider making an alias!\033[0m"
|
||||
fi
|
||||
}
|
||||
bindkey -s '^o' 'lfcd\n'
|
||||
preexec_functions+=(alias_suggestion_check)
|
||||
|
||||
function remind_alias_if_exists() {
|
||||
local current_cmd="$1"
|
||||
|
||||
if [[ -z "$current_cmd" || ${#current_cmd} -lt 7 ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
local matched_alias=""
|
||||
for alias_name expansion in ${(kv)aliases}; do
|
||||
if [[ ${#alias_name} -gt ${#expansion} ]]; then
|
||||
continue
|
||||
fi
|
||||
if [[ "$current_cmd" == "$expansion" ]]; then
|
||||
echo
|
||||
echo -e "\033[33m[ALIAS REMINDER]: You just ran '$current_cmd', which has an alias '$alias_name'.\033[0m"
|
||||
echo -e "\033[33mTry using: $alias_name\033[0m"
|
||||
echo
|
||||
return
|
||||
fi
|
||||
if [[ "$current_cmd" == "$expansion"* ]] && [[ ${#expansion} > ${#matched_alias} ]]; then
|
||||
matched_alias="$alias_name"
|
||||
fi
|
||||
done
|
||||
if [[ -n $matched_alias ]]; then
|
||||
local expansion="${aliases[$matched_alias]}"
|
||||
echo
|
||||
echo -e "\033[33m[ALIAS REMINDER]: You just ran '$current_cmd', which matched an existing alias $matched_alias='$expansion'.\033[0m"
|
||||
echo -e "\033[33mTry using: $matched_alias${current_cmd#$expansion}\033[0m"
|
||||
echo
|
||||
fi
|
||||
}
|
||||
preexec_functions+=(remind_alias_if_exists)
|
||||
|
||||
|
||||
bindkey -s '^a' 'bc -lq\n'
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ printf "# vim: filetype=sh\\nalias " > "$shell_shortcuts"
|
||||
# Format the `directories` file in the correct syntax and sent it to all three configs.
|
||||
eval "echo \"$(cat "$bmdirs")\"" | \
|
||||
awk "!/^\s*#/ && !/^\s*\$/ {gsub(\"\\\s*#.*$\",\"\");
|
||||
printf(\"%s=\42cd %s && ls -a\42 \\\\\n\",\$1,\$2) >> \"$shell_shortcuts\" ;
|
||||
printf(\"%s=\42cd %s && ls\42 \\\\\n\",\$1,\$2) >> \"$shell_shortcuts\" ;
|
||||
printf(\"hash -d %s=%s \n\",\$1,\$2) >> \"$zsh_named_dirs\" ;
|
||||
printf(\"map C%s cd \42%s\42 \n\",\$1,\$2) >> \"$lf_shortcuts\" }"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user