Table of contents:
setopt interactivecomments
setopt auto_cd
Binding to Alt-Enter here, use whatever you wish
function _fuzzy_search_current_word() {
CURRENTWORD="${LBUFFER/* /}${RBUFFER/ */}"
# If there is no world entered, do nothing
[[ -z $CURRENTWORD ]] && return
# Pass current subtree to skim
# SKIMRESULT=`find . | sk -q $CURRENTWORD`
# ripgrep seems faster
SKIMRESULT=`rg --files --no-ignore-vcs --hidden | sk -q $CURRENTWORD`
# Replace the word with selected result
BUFFER=`echo "$BUFFER" | sed "s#${CURRENTWORD}#${SKIMRESULT}#"`
zle end-of-line
}
# Bindkey should be initialized before
# Normally this is not an issue,
# but hacks like tmux doesn't work with this for some bullshit reason
bindkey -e
# Check and enable if we have skim in PATH, if yes, enable the function
if type "sk" > /dev/null 2>&1; then
zle -N _fuzzy_search_current_word
# Shortcut for fuzzy = Alt - enter
bindkey '^[^M' _fuzzy_search_current_word
fi
Who likes it anyway?
setopt NO_BEEP
Requirements: toilet (for visual purposes)
Usage: fuck nautilus
(or any other unique term to grep process)
function fuck() {
VICTIMS=`pgrep -a $1`
if [[ "${VICTIMS}" != "" ]];then
echo "Found processes:\n${VICTIMS}"
echo "kill? (y/N)"
read isKill
if [[ $isKill == "y" ]]; then
pkill -9 $1 > /dev/null 2>&1
echo "\n (╯°□°)╯︵$(echo "$1"|toilet -f term -F rotate)\n"
fi
fi
}
Usage: random_number 200
(or any other value as top limit)
function random_number() {
if [[ "$1" == "" ]]; then
echo "I need a number as top value"
else
echo $[${RANDOM}%$1]
fi
}
compctl -/ cd
setopt rm_star_silent
Forgot to type sudo on your current or last command?
Just press Esc twice.. Or whatever shortcut you bind.
sudo-command-line() {
[[ -z $BUFFER ]] && zle up-history
if [[ $BUFFER == sudo\ * ]]; then
LBUFFER="${LBUFFER#sudo }"
elif [[ $BUFFER == $EDITOR\ * ]]; then
LBUFFER="${LBUFFER#$EDITOR }"
LBUFFER="sudoedit $LBUFFER"
elif [[ $BUFFER == sudoedit\ * ]]; then
LBUFFER="${LBUFFER#sudoedit }"
LBUFFER="$EDITOR $LBUFFER"
else
LBUFFER="sudo $LBUFFER"
fi
}
zle -N sudo-command-line
# Defined shortcut keys: [Esc] [Esc]
bindkey "\e\e" sudo-command-line
I wanted this because I don't like to have a sticky RPROMPT which causes problems on copy/paste.
Be aware that you can also achieve command timings with: fc -liD
This will print the start time right after the command, but only if you finish the command with a semicolon.
showshow () {
if [[ "${1}" != *";" ]]; then
return
fi
DATE="# started at $( date +'%Y/%m/%d %H:%M:%S' )"
local len_prompt=$( strlen "$PROMPT" )
local len_command=$( strlen "${1}" )
local start_from=$(($len_prompt + $len_command + 2))
local len_cmd=$( strlen "$@" )
local len_prompt=$(strlen "$PROMPT" )
local len_left=$(($len_cmd+$len_prompt))
RDATE="\033[${start_from}C ${DATE}"
echo -e "\033[1A${RDATE}"
}
preexec_functions=($preexec_functions showshow)