diff options
Diffstat (limited to 'base/.zsh')
-rw-r--r-- | base/.zsh/aliases.zsh | 12 | ||||
-rw-r--r-- | base/.zsh/functions.zsh | 12 | ||||
-rw-r--r-- | base/.zsh/tipz.zsh | 84 |
3 files changed, 105 insertions, 3 deletions
diff --git a/base/.zsh/aliases.zsh b/base/.zsh/aliases.zsh index 9f1d2a1..ad56e1b 100644 --- a/base/.zsh/aliases.zsh +++ b/base/.zsh/aliases.zsh @@ -5,12 +5,22 @@ alias less='less -R' alias grep='grep --color=auto' alias ..='cd ../' +alias sudoe="sudo -E" +alias svim="sudo -E vim" +alias svimdiff="sudo -E vimdiff" + # GIT alias gd='git diff' alias gco='git checkout' -alias gs='git status' +alias gs='git status --short' alias gl='git pull' alias gp='git push' alias gpp='git pull; git push' alias gwc='git whatchanged -p --abbrev-commit --pretty=medium' + +# POWER + +alias reboot="systemctl reboot" +alias shutdown="systemctl poweroff" +alias poweroff="systemctl poweroff" diff --git a/base/.zsh/functions.zsh b/base/.zsh/functions.zsh index 7c405f0..4606c13 100644 --- a/base/.zsh/functions.zsh +++ b/base/.zsh/functions.zsh @@ -1,10 +1,18 @@ -todo () { +function todo { a="" for i; do a="$a,$i"; done a="{$(echo "$a" | cut -d',' -f2-)}" echo "grep -R --exclude-dir=$a TODO | sed -e 's/.*TODO //;s/ \*\/$//;s/ -->//' | LC_ALL=C sort -u" | zsh } -which () { +function which { (alias; declare -f) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot $@ } #export -f which + +function trash { + mkdir "$HOME/.trash" + for file in "$@"; do + mv "$file" "$HOME/.trash/$(basename $file).$(date +%Y%m%d-%H%M%S)" + done +} # Add this to your crontab: +# 43 0 * * 3 find ~/.trash -type f -mtime +90 -delete diff --git a/base/.zsh/tipz.zsh b/base/.zsh/tipz.zsh new file mode 100644 index 0000000..bb1e224 --- /dev/null +++ b/base/.zsh/tipz.zsh @@ -0,0 +1,84 @@ +### +# Search the defined aliases for a match +### +function _tipz_find_match() { + local bits alias command result="" + local -a aliases args; args="$@" + + # Load the current aliases into an array + local oldIFS=$IFS + IFS=$'\n' aliases=($(alias)) + IFS=$oldIFS + + # Loop through each of the aliases + for line in "${aliases[@]}"; do + # Split the line on '=' to separate the command + # and its alias + bits=("${(s/=/)line}") + alias=$bits[1] + command=$bits[2] + + # Create a regex that finds an exact match for + # the current argument string + args="${(@)args[@]}" + local pattern=$'^[\'\"]?'${args//([\{\}\(\)\[\]\*\?\:\\\.\|])/\\\$1}$'[\'\"]?$' + + # Check if the command matches the regex + if [[ "$command" =~ $pattern ]]; then + # Ensure that the longest matching command is stored + if [[ ${#command} > ${#result} ]]; then + result=$alias + fi + fi + done + + # If a result has been found, output it + if [[ -n $result ]]; then + echo $result + return 0 + fi + + return 1 +} + +### +# Search for alias tips for the currently executing command +### +function _tipz_process { + local -a cmd; cmd=($@) + integer i=$(( ${#cmd} + 1 )) + + # Loop for the length of the argument list, knocking + # an argument from the end of the list each time, and + # then using the remaining arguments to search for aliases + while [[ $i > 0 ]]; do + # Check the current string for a match + result=$(_tipz_find_match "${(@)cmd:0:$i}") + + # If the search exited successfully, + # output the tip to the user + if [[ $? -eq 0 ]]; then + print -P "%B%F{8}Alias tip: %b$result ${(@)cmd:$i}%f" + return 0 + fi + + # Decrement the counter + i=$(( i - 1 )) + done + + return 1 +} + +### +# A small function to filter out strange arguments +# sent from the add-zsh-hook preexec hook +### +function _tipz_prexec() { + _tipz_process $(echo $1) +} + +### +# Register the preexec hook +### +autoload -Uz add-zsh-hook +add-zsh-hook preexec _tipz_prexec |