Skip to content

Commit

Permalink
Zsh: Optimize aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
alfunx committed Oct 23, 2017
1 parent 9ce3d85 commit a8011bd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
41 changes: 26 additions & 15 deletions .zsh_aliases
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ toilol() {
toilet -f mono12 -w "$(tput cols)" | lolcat
}

pacman() {
local pattern="^-S[cuy]|^-S$|^-R[sn]|^-U"
if [[ "$1" =~ $pattern ]]; then
sudo /usr/bin/pacman $@
else
/usr/bin/pacman $@
fi
}

##########
# tmux #
##########
Expand Down Expand Up @@ -109,16 +118,20 @@ fag() {

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

# fd - fda including hidden directories
fd() {
local dir
dir=$(find -L ${1:-.} -type d 2> /dev/null \
| fzf-tmux -d 30% +m -q "$1" -0) && cd "$dir"
cd "$(find -L ${1:-.} -type d 2>/dev/null \
| fzf-tmux -d 30% +m -q "$1" -0)"
}

# fr - cd to selected directory and open ranger
fr() {
cd "$(find -L ${1:-.} -type d 2>/dev/null \
| fzf-tmux -d 30% +m -q "$1" -0)" && ranger
}

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

# example usage: pacman -S $(fp)
fp() {
local packages package package_name arg
local arg
arg="-Ss"
if (( $# > 0 )); then
arg="$@"
fi
packages=$(pacman "$arg" | sed 'N;s/\n//') &&
package=$(echo "$packages" | fzf-tmux -d 30% -m) &&
package_name=$(echo "$package" | sed 's/.*\///' | sed 's/ .*//') &&
echo -n "$package_name"
echo -n "$(pacman $arg \
| sed 'N;s/\n//' \
| fzf-tmux -d 30% -m \
| sed 's/.*\///' \
| sed 's/ .*//')"
}

######################
# fuzzy man search #
######################

fman() {
local manpage manpage_name
manpage=$(apropos . | less | fzf-tmux -d 30%) &&
manpage_name=$(echo "$manpage" | sed 's/ .*//') &&
man "$manpage_name"
man "$(apropos . | fzf-tmux -d 30% | sed 's/ .*//')"
}

#####################
Expand Down
6 changes: 3 additions & 3 deletions .zshrc
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@ source /home/amariya/.vim/plugged/gruvbox/gruvbox_256palette.sh
export LESS_TERMCAP_mb=$'\e[1;31m'
export LESS_TERMCAP_md=$'\e[1;34m'
export LESS_TERMCAP_me=$'\e[0m'
export LESS_TERMCAP_se=$'\e[0m'
export LESS_TERMCAP_so=$'\e[0;30m\e[48;5;208m'
export LESS_TERMCAP_ue=$'\e[0m'
export LESS_TERMCAP_se=$'\e[0m'
export LESS_TERMCAP_us=$'\e[1;35m'
export LESS_TERMCAP_ue=$'\e[0m'
export LESS='-iMRj.5'

# Alternative prompt
Expand Down Expand Up @@ -170,7 +170,7 @@ export FZF_CTRL_R_OPTS="--no-reverse"
export FZF_ALT_C_OPTS="--no-reverse"

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

Expand Down

0 comments on commit a8011bd

Please sign in to comment.