Cleanup zsh functions and add unbkp()
Add unbkp() that reverses bkp(). Use shorter zsh syntax for disowning a background job. Add usage string to mangrep. Expect clang-format config to be in XDG_CONFIG_HOME. Add functionality of comments. Use `command` where we want a command to be taken as external.
This commit is contained in:
@@ -9,7 +9,13 @@ function cl() {
|
|||||||
## Copy file and append .bkp extension
|
## Copy file and append .bkp extension
|
||||||
function bkp() {
|
function bkp() {
|
||||||
for file in "$@"; do
|
for file in "$@"; do
|
||||||
cp -i "$file" "$file.bkp"
|
command cp -i "$file" "$file.bkp"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
unbkp() {
|
||||||
|
for file in "$@"; do
|
||||||
|
command cp -i "$file" "${file%.bkp}"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -18,7 +24,7 @@ function launch() {
|
|||||||
# eval "$@" ## does not work with special characters?
|
# eval "$@" ## does not work with special characters?
|
||||||
launch_command="$1"
|
launch_command="$1"
|
||||||
shift
|
shift
|
||||||
$launch_command "$@" &>/dev/null & disown
|
$launch_command "$@" &>/dev/null &|
|
||||||
}
|
}
|
||||||
|
|
||||||
## Compares two pdfs based on the result of pdftotext
|
## Compares two pdfs based on the result of pdftotext
|
||||||
@@ -287,12 +293,14 @@ function resolve() {
|
|||||||
|
|
||||||
## Grep a keyword at the beginning of a line (ignoring whitespace) in a man page
|
## Grep a keyword at the beginning of a line (ignoring whitespace) in a man page
|
||||||
function mangrep() {
|
function mangrep() {
|
||||||
mangrep_file="$1"
|
if [ $# -lt 2 ]; then
|
||||||
mangrep_pattern="$2"
|
printf "usage: mangrep <man page> <pattern> [<man flags>]\n" >&2
|
||||||
shift
|
printf "example: mangrep bash \"(declare|typeset)\"\n" >&2
|
||||||
shift
|
return 1
|
||||||
man -P 'less -p "^ *'"${mangrep_pattern}\"" "$@" "${mangrep_file}"
|
fi
|
||||||
unset mangrep_{file,pattern}
|
local page="$1" pattern="$2"
|
||||||
|
shift 2
|
||||||
|
man -P "less -p \"^ *${pattern}\"" "$@" "${file}"
|
||||||
}
|
}
|
||||||
|
|
||||||
## Grep in zsh history file
|
## Grep in zsh history file
|
||||||
@@ -300,10 +308,15 @@ function histgrep() {
|
|||||||
grep "$@" "${HISTFILE:-$HOME/.zsh_history}"
|
grep "$@" "${HISTFILE:-$HOME/.zsh_history}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function format() {
|
function cformat() {
|
||||||
# TODO: respect manual changes made in meld
|
# TODO: respect manual changes made in meld
|
||||||
CLANG_FORMAT_FILE="$HOME/Projects/C/.clang.format"
|
CLANG_FORMAT_FILE="${XDG_CONFIG_HOME:-$HOME/.config}/clang/config"
|
||||||
FORMAT="{$(sed -E '/^\s*$/d' "$CLANG_FORMAT_FILE" | tr '\n' ',' | sed 's/,$//')}"
|
FORMAT="$(
|
||||||
|
sed -E '/^\s*($|#)/d' "$CLANG_FORMAT_FILE" \
|
||||||
|
| tr '\n' ',' \
|
||||||
|
| sed 's/,$//'
|
||||||
|
)"
|
||||||
|
FORMAT="{${FORMAT}}"
|
||||||
if [ $# -eq 1 ]; then
|
if [ $# -eq 1 ]; then
|
||||||
meld <(clang-format -style="$FORMAT" $1) $1
|
meld <(clang-format -style="$FORMAT" $1) $1
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -4,18 +4,18 @@
|
|||||||
## List items in trash if no argument is specified
|
## List items in trash if no argument is specified
|
||||||
function _trash_list_default() {
|
function _trash_list_default() {
|
||||||
if [ $# -eq 0 ]; then
|
if [ $# -eq 0 ]; then
|
||||||
trash-list
|
command trash-list
|
||||||
else
|
else
|
||||||
\trash "$@"
|
command trash "$@"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
## Open nemo in current directory if no argument is specified
|
## Open nemo in current directory if no argument is specified
|
||||||
function _nemo_wd_default() {
|
function _nemo_wd_default() {
|
||||||
if [ $# -eq 0 ]; then
|
if [ $# -eq 0 ]; then
|
||||||
\nemo ./
|
command nemo ./
|
||||||
else
|
else
|
||||||
\nemo "$@"
|
command nemo "$@"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user