Adding aliases and stuff
This commit is contained in:
@@ -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'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user