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
|
||||
function bkp() {
|
||||
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
|
||||
}
|
||||
|
||||
@@ -18,7 +24,7 @@ function launch() {
|
||||
# eval "$@" ## does not work with special characters?
|
||||
launch_command="$1"
|
||||
shift
|
||||
$launch_command "$@" &>/dev/null & disown
|
||||
$launch_command "$@" &>/dev/null &|
|
||||
}
|
||||
|
||||
## 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
|
||||
function mangrep() {
|
||||
mangrep_file="$1"
|
||||
mangrep_pattern="$2"
|
||||
shift
|
||||
shift
|
||||
man -P 'less -p "^ *'"${mangrep_pattern}\"" "$@" "${mangrep_file}"
|
||||
unset mangrep_{file,pattern}
|
||||
if [ $# -lt 2 ]; then
|
||||
printf "usage: mangrep <man page> <pattern> [<man flags>]\n" >&2
|
||||
printf "example: mangrep bash \"(declare|typeset)\"\n" >&2
|
||||
return 1
|
||||
fi
|
||||
local page="$1" pattern="$2"
|
||||
shift 2
|
||||
man -P "less -p \"^ *${pattern}\"" "$@" "${file}"
|
||||
}
|
||||
|
||||
## Grep in zsh history file
|
||||
@@ -300,10 +308,15 @@ function histgrep() {
|
||||
grep "$@" "${HISTFILE:-$HOME/.zsh_history}"
|
||||
}
|
||||
|
||||
function format() {
|
||||
function cformat() {
|
||||
# TODO: respect manual changes made in meld
|
||||
CLANG_FORMAT_FILE="$HOME/Projects/C/.clang.format"
|
||||
FORMAT="{$(sed -E '/^\s*$/d' "$CLANG_FORMAT_FILE" | tr '\n' ',' | sed 's/,$//')}"
|
||||
CLANG_FORMAT_FILE="${XDG_CONFIG_HOME:-$HOME/.config}/clang/config"
|
||||
FORMAT="$(
|
||||
sed -E '/^\s*($|#)/d' "$CLANG_FORMAT_FILE" \
|
||||
| tr '\n' ',' \
|
||||
| sed 's/,$//'
|
||||
)"
|
||||
FORMAT="{${FORMAT}}"
|
||||
if [ $# -eq 1 ]; then
|
||||
meld <(clang-format -style="$FORMAT" $1) $1
|
||||
fi
|
||||
|
||||
@@ -4,18 +4,18 @@
|
||||
## List items in trash if no argument is specified
|
||||
function _trash_list_default() {
|
||||
if [ $# -eq 0 ]; then
|
||||
trash-list
|
||||
command trash-list
|
||||
else
|
||||
\trash "$@"
|
||||
command trash "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
## Open nemo in current directory if no argument is specified
|
||||
function _nemo_wd_default() {
|
||||
if [ $# -eq 0 ]; then
|
||||
\nemo ./
|
||||
command nemo ./
|
||||
else
|
||||
\nemo "$@"
|
||||
command nemo "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user