-
Notifications
You must be signed in to change notification settings - Fork 0
/
alias
108 lines (87 loc) · 2.97 KB
/
alias
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/bin/zsh
#####################################################################
### basic alias #####################################################
#####################################################################
alias pd='pushd'
alias qd='popd'
alias lsd='dirs'
alias pdo='pwd | xclip' # [p]aste [d]irectory [o]n clipboard
alias cdo='cd $(xclip -o)' # [c]hange to [d]irectory [o]n clipboard
#####################################################################
### default command override ########################################
#####################################################################
alias ls='ls --color=auto --group-directories-first'
command -v bat >/dev/null 2>&1 \
&& alias cat='bat --style="plain"'
command -v startplasma-x11 >/dev/null 2>&1 \
&& alias startk="startx '$DOTWRYN/config/xinitrc.kde'"
command -v i3 >/dev/null 2>&1 \
&& alias starti="startx '$DOTWRYN/config/xinitrc.i3'"
#####################################################################
### fancy alias (not technically an "alias" but makes sense here) ###
#####################################################################
w() { # fancy(?) version of "alias w='watch -tcn1 '"
local WATCH_ARGS=()
WATCH_ARGS+=(--no-title)
WATCH_ARGS+=(--color)
WATCH_ARGS+=(--interval 1)
# don't add delay if command is available to /bin/sh
/bin/sh -c "command -v $1" >/dev/null 2>&1 && {
watch ${WATCH_ARGS[@]} $@
return $?
}
# quickly reduce first-order aliases
alias $1 >/dev/null 2>&1 && {
watch ${WATCH_ARGS[@]} $(which $1 | sed 's/.*aliased to //') ${@:2}
return $?
}
# import zshrc and inject current environment
watch ${WATCH_ARGS[@]} "zsh -c 'source ~/.zshrc >/dev/null 2>&1; $(while read e; do printf 'export '; printf '%q ' "$e"; echo; done < <(env) | grep '='); echo \" $@\n---------------------------------------------------- \$(date +%H:%m:%S)\"; $@'"
}
erg() { # [e]dit files with [r]ip[g]rep matches
$EDITOR $(rg --color=never --files-with-matches $@)
}
fix() { # [fix] merge conflicts
local PREFIX="$(git rev-parse --show-toplevel)"
[ $PREFIX ] || return 128
local FILE FILES=()
for FILE in $(git diff --name-only 2>/dev/null | sort -u)
do
echo "diff detected in $(basename -- $(dirname -- "$FILE"))/$(basename -- "$FILE")" >&2
FILES+=("$PREFIX/$FILE")
done
[[ ${#FILES[@]} -eq 0 ]] && {
echo "no merge conflicts detected"
return 0
}
$EDITOR ${FILES[@]}
}
restart() { # reload zshrc with some bonus options
local _S EXECUTION_MODE=quiet
while [[ $# -gt 0 ]]
do
_S=1
case $1 in
( -h | --help ) which restart; return 0 ;;
( -v | --verbose ) EXECUTION_MODE=verbose ;;
( -l | --login ) EXECUTION_MODE=login ;;
esac
shift $_S
done
case $EXECUTION_MODE in
login )
echo "--- fresh start c: ---" >&2
zsh -l
echo "--- fresh end :c ---" >&2
;;
verbose )
source "$HOME/.zshrc"
;;
quiet )
clear
source "$HOME/.zshrc" 2>/dev/null
;;
esac
}
#####################################################################
return 0