Adding aliases and stuff
This commit is contained in:
@@ -26,7 +26,42 @@ alias \
|
|||||||
|
|
||||||
# Colorize commands when possible.
|
# Colorize commands when possible.
|
||||||
alias \
|
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" \
|
grep="grep --color=auto" \
|
||||||
diff="diff --color=auto" \
|
diff="diff --color=auto" \
|
||||||
ccat="highlight --out-format=ansi"
|
ccat="highlight --out-format=ansi"
|
||||||
@@ -41,18 +76,22 @@ alias \
|
|||||||
cl="clear" \
|
cl="clear" \
|
||||||
p="sudo pacman" \
|
p="sudo pacman" \
|
||||||
z="zathura" \
|
z="zathura" \
|
||||||
ll="ls -l" \
|
ll="ls -AhlFt --group-directories-first --time=atime --color=auto --time-style=long-iso" \
|
||||||
la="ls -al" \
|
|
||||||
ag="alias | grep" \
|
ag="alias | grep" \
|
||||||
lc="clone_from_labs" \
|
lc="clone_from_labs" \
|
||||||
gc="clone_from_github" \
|
gc="clone_from_github" \
|
||||||
dgit="git --git-dir ~/.config/dotfiles/.git --work-tree=$HOME" \
|
dgit="git --git-dir ~/.config/dotfiles/.git --work-tree=$HOME" \
|
||||||
.z="source ~/.config/shell/profile" \
|
.z="source ~/.config/shell/profile" \
|
||||||
|
.a="source ~/.config/shell/aliasrc" \
|
||||||
testmic="arecord -vv -f dat /dev/null"
|
testmic="arecord -vv -f dat /dev/null"
|
||||||
|
|
||||||
# Dev
|
# Dev
|
||||||
alias \
|
alias \
|
||||||
sail='[ -f sail ] && sh sail || sh vendor/bin/sail'
|
sail='[ -f sail ] && sh sail || sh vendor/bin/sail'
|
||||||
|
yi="yarn install"
|
||||||
|
y="yarn"
|
||||||
|
ci="composer install"
|
||||||
|
c="composer"
|
||||||
|
|
||||||
# Translating
|
# Translating
|
||||||
alias \
|
alias \
|
||||||
@@ -61,13 +100,43 @@ alias \
|
|||||||
enr="trans en:ro -j -- " \
|
enr="trans en:ro -j -- " \
|
||||||
enri="trans en:ro -i"
|
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
|
# Clone from labs
|
||||||
function clone_from_labs() {
|
function cll() {
|
||||||
git clone "git@labs.scarif.space:chris/$1" "${@:2}"
|
git clone "git@labs.scarif.space:chris/$1" "${@:2}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Clone from github
|
# Clone from github
|
||||||
function clone_from_github() {
|
function clg() {
|
||||||
git clone "https://github.com/$1" "${@:2}"
|
git clone "https://github.com/$1" "${@:2}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -99,17 +99,53 @@ preexec() {
|
|||||||
echo -ne '\e[5 q'
|
echo -ne '\e[5 q'
|
||||||
}
|
}
|
||||||
|
|
||||||
# Use lf to switch directories and bind it to ctrl-o
|
function alias_suggestion_check() {
|
||||||
lfcd() {
|
local current_cmd="$1"
|
||||||
tmp="$(mktemp)"
|
|
||||||
lf -last-dir-path="$tmp" "$@"
|
if [[ -z "$current_cmd" || ${#current_cmd} -lt 7 ]]; then
|
||||||
if [ -f "$tmp" ]; then
|
return
|
||||||
dir="$(cat "$tmp")"
|
fi
|
||||||
rm -f "$tmp" >/dev/null
|
|
||||||
[ -d "$dir" ] && [ "$dir" != "$(pwd)" ] && cd "$dir"
|
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
|
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'
|
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.
|
# Format the `directories` file in the correct syntax and sent it to all three configs.
|
||||||
eval "echo \"$(cat "$bmdirs")\"" | \
|
eval "echo \"$(cat "$bmdirs")\"" | \
|
||||||
awk "!/^\s*#/ && !/^\s*\$/ {gsub(\"\\\s*#.*$\",\"\");
|
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(\"hash -d %s=%s \n\",\$1,\$2) >> \"$zsh_named_dirs\" ;
|
||||||
printf(\"map C%s cd \42%s\42 \n\",\$1,\$2) >> \"$lf_shortcuts\" }"
|
printf(\"map C%s cd \42%s\42 \n\",\$1,\$2) >> \"$lf_shortcuts\" }"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user