zsh: Convert all oneline functions into aliases
Convert all functions that are pretty much oneliners and do not contain any real logic into aliases by using anonymous functions. I am not too sure if I will keep it this way.
This commit is contained in:
@@ -43,6 +43,7 @@
|
|||||||
alias l="${aliases[ls]:-ls} -lh --time-style=long-iso"
|
alias l="${aliases[ls]:-ls} -lh --time-style=long-iso"
|
||||||
alias ll="${aliases[l]} -A"
|
alias ll="${aliases[l]} -A"
|
||||||
alias cd..='cd ..'
|
alias cd..='cd ..'
|
||||||
|
alias cl='() { cd "$@" && ${aliases[ls]:-[ls]}'
|
||||||
alias getclip="xclip -selection c -o"
|
alias getclip="xclip -selection c -o"
|
||||||
alias setclip="perl -pe 'chomp if eof' | xclip -selection c"
|
alias setclip="perl -pe 'chomp if eof' | xclip -selection c"
|
||||||
alias pdf='launch evince'
|
alias pdf='launch evince'
|
||||||
@@ -84,6 +85,22 @@
|
|||||||
# List options and their value (on|off) line by line. This makes it a lot
|
# List options and their value (on|off) line by line. This makes it a lot
|
||||||
# easier to grep for activated options than using `setopt` and `unsetopt`.
|
# easier to grep for activated options than using `setopt` and `unsetopt`.
|
||||||
alias listopts='printf "%s %s\n" "${(kv)options[@]}"'
|
alias listopts='printf "%s %s\n" "${(kv)options[@]}"'
|
||||||
|
# Launch program independent and detached from shell.
|
||||||
|
alias launch='() { ${aliases[$1]:-$1} "${@[2,-1]}" &>/dev/null &| }'
|
||||||
|
# Create copy with .bkp extension
|
||||||
|
alias bkp='() { for f; do command cp -i "$f"{,.bkp}; done }'
|
||||||
|
# Reverse bkp()
|
||||||
|
alias unbkp='() { for f; do command cp -i "$f" "${f%.bkp}; done }'
|
||||||
|
# Grep in history file
|
||||||
|
alias histgrep='() { grep "$@" "${HISTFILE:-$HOME/.zsh_history}" }'
|
||||||
|
# URL-encode
|
||||||
|
alias urlenc='() {
|
||||||
|
python3 -c "from urllib import parse; print(parse.quote('$@'), end='')
|
||||||
|
}'
|
||||||
|
# URL-decode
|
||||||
|
alias urldec='() {
|
||||||
|
python3 -c "from urllib import parse; print(parse.unquote('$@'), end='')
|
||||||
|
}'
|
||||||
|
|
||||||
# Named directories
|
# Named directories
|
||||||
hash -d docs="$HOME"/Documents/
|
hash -d docs="$HOME"/Documents/
|
||||||
|
|||||||
@@ -1,32 +1,6 @@
|
|||||||
## Author: druckdev
|
## Author: druckdev
|
||||||
## Created: 2019-08-28
|
## Created: 2019-08-28
|
||||||
|
|
||||||
## change into dir and print accordingly
|
|
||||||
function cl() {
|
|
||||||
cd "$@" && ls
|
|
||||||
}
|
|
||||||
|
|
||||||
## Copy file and append .bkp extension
|
|
||||||
function bkp() {
|
|
||||||
for file in "$@"; do
|
|
||||||
command cp -i "$file" "$file.bkp"
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
unbkp() {
|
|
||||||
for file in "$@"; do
|
|
||||||
command cp -i "$file" "${file%.bkp}"
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
## Launches program and detaches it from the shell
|
|
||||||
function launch() {
|
|
||||||
# eval "$@" ## does not work with special characters?
|
|
||||||
launch_command="$1"
|
|
||||||
shift
|
|
||||||
$launch_command "$@" &>/dev/null &|
|
|
||||||
}
|
|
||||||
|
|
||||||
## Compares two pdfs based on the result of pdftotext
|
## Compares two pdfs based on the result of pdftotext
|
||||||
function pdfdiff() {
|
function pdfdiff() {
|
||||||
if [[ $# -eq 2 && -r "$1" && -r "$2" ]]; then
|
if [[ $# -eq 2 && -r "$1" && -r "$2" ]]; then
|
||||||
@@ -304,19 +278,6 @@ function mangrep() {
|
|||||||
man -P "less -p \"^ *${pattern}\"" "$@" "${file}"
|
man -P "less -p \"^ *${pattern}\"" "$@" "${file}"
|
||||||
}
|
}
|
||||||
|
|
||||||
## Grep in zsh history file
|
|
||||||
function histgrep() {
|
|
||||||
grep "$@" "${HISTFILE:-$HOME/.zsh_history}"
|
|
||||||
}
|
|
||||||
|
|
||||||
function urlenc() {
|
|
||||||
python3 -c "from urllib import parse; print(parse.quote('$@'), end='')"
|
|
||||||
}
|
|
||||||
|
|
||||||
function urldec() {
|
|
||||||
python3 -c "from urllib import parse; print(parse.unquote('$@'), end='')"
|
|
||||||
}
|
|
||||||
|
|
||||||
safe-remove() {
|
safe-remove() {
|
||||||
[ $# -gt 0 ] || return 1
|
[ $# -gt 0 ] || return 1
|
||||||
[ -e "$1" ] || return 1
|
[ -e "$1" ] || return 1
|
||||||
|
|||||||
Reference in New Issue
Block a user