Skip to content

Commit a8011bd

Browse files
committed
Zsh: Optimize aliases
1 parent 9ce3d85 commit a8011bd

File tree

2 files changed

+29
-18
lines changed

2 files changed

+29
-18
lines changed

.zsh_aliases

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,15 @@ toilol() {
7575
toilet -f mono12 -w "$(tput cols)" | lolcat
7676
}
7777

78+
pacman() {
79+
local pattern="^-S[cuy]|^-S$|^-R[sn]|^-U"
80+
if [[ "$1" =~ $pattern ]]; then
81+
sudo /usr/bin/pacman $@
82+
else
83+
/usr/bin/pacman $@
84+
fi
85+
}
86+
7887
##########
7988
# tmux #
8089
##########
@@ -109,16 +118,20 @@ fag() {
109118

110119
# fda - cd to selected directory
111120
fda() {
112-
local dir
113-
dir=$(find ${1:-.} -path '*/\.*' -prune -o -type d -print 2> /dev/null \
114-
| fzf-tmux -d 30% +m -q "$1" -0) && cd "$dir"
121+
cd "$(find ${1:-.} -path '*/\.*' -prune -o -type d -print 2>/dev/null \
122+
| fzf-tmux -d 30% +m -q "$1" -0)"
115123
}
116124

117125
# fd - fda including hidden directories
118126
fd() {
119-
local dir
120-
dir=$(find -L ${1:-.} -type d 2> /dev/null \
121-
| fzf-tmux -d 30% +m -q "$1" -0) && cd "$dir"
127+
cd "$(find -L ${1:-.} -type d 2>/dev/null \
128+
| fzf-tmux -d 30% +m -q "$1" -0)"
129+
}
130+
131+
# fr - cd to selected directory and open ranger
132+
fr() {
133+
cd "$(find -L ${1:-.} -type d 2>/dev/null \
134+
| fzf-tmux -d 30% +m -q "$1" -0)" && ranger
122135
}
123136

124137
# fo - Open the selected file with the default editor
@@ -291,26 +304,24 @@ fstash() {
291304

292305
# example usage: pacman -S $(fp)
293306
fp() {
294-
local packages package package_name arg
307+
local arg
295308
arg="-Ss"
296309
if (( $# > 0 )); then
297310
arg="$@"
298311
fi
299-
packages=$(pacman "$arg" | sed 'N;s/\n//') &&
300-
package=$(echo "$packages" | fzf-tmux -d 30% -m) &&
301-
package_name=$(echo "$package" | sed 's/.*\///' | sed 's/ .*//') &&
302-
echo -n "$package_name"
312+
echo -n "$(pacman $arg \
313+
| sed 'N;s/\n//' \
314+
| fzf-tmux -d 30% -m \
315+
| sed 's/.*\///' \
316+
| sed 's/ .*//')"
303317
}
304318

305319
######################
306320
# fuzzy man search #
307321
######################
308322

309323
fman() {
310-
local manpage manpage_name
311-
manpage=$(apropos . | less | fzf-tmux -d 30%) &&
312-
manpage_name=$(echo "$manpage" | sed 's/ .*//') &&
313-
man "$manpage_name"
324+
man "$(apropos . | fzf-tmux -d 30% | sed 's/ .*//')"
314325
}
315326

316327
#####################

.zshrc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,10 @@ source /home/amariya/.vim/plugged/gruvbox/gruvbox_256palette.sh
134134
export LESS_TERMCAP_mb=$'\e[1;31m'
135135
export LESS_TERMCAP_md=$'\e[1;34m'
136136
export LESS_TERMCAP_me=$'\e[0m'
137-
export LESS_TERMCAP_se=$'\e[0m'
138137
export LESS_TERMCAP_so=$'\e[0;30m\e[48;5;208m'
139-
export LESS_TERMCAP_ue=$'\e[0m'
138+
export LESS_TERMCAP_se=$'\e[0m'
140139
export LESS_TERMCAP_us=$'\e[1;35m'
140+
export LESS_TERMCAP_ue=$'\e[0m'
141141
export LESS='-iMRj.5'
142142

143143
# Alternative prompt
@@ -170,7 +170,7 @@ export FZF_CTRL_R_OPTS="--no-reverse"
170170
export FZF_ALT_C_OPTS="--no-reverse"
171171

172172
# TMUX
173-
if [ "$(ps aux | pgrep termite | wc -l)" -eq "1" ]; then
173+
if [ "$(pgrep termite | wc -l)" -eq "1" ] && [[ "$TERM" == "xterm-termite" ]]; then
174174
tmux attach > /dev/null 2&>1 || tmux new > /dev/null 2&>1
175175
fi
176176

0 commit comments

Comments
 (0)