Skip to content

Instantly share code, notes, and snippets.

@leomao
Last active September 29, 2017 10:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leomao/d13c5e2e11e4cd67f0d484b203eddc01 to your computer and use it in GitHub Desktop.
Save leomao/d13c5e2e11e4cd67f0d484b203eddc01 to your computer and use it in GitHub Desktop.
Use fzf to filter and select the search result from pacman (or pacaur)
#!/bin/bash
if [[ -z $(command -v fzf) ]]; then
echo "You don't have fzf!!"
exit -1
fi
# collapse pacaur search result into oneline each entry
collapse() {
head=''
rest=''
first=1
while IFS='' read -r line || [[ -n "$line" ]]; do
if [[ ${line:0:1} == " " ]]; then
rest="$rest $line"
else
if [[ $first -ne 1 ]]; then
printf "%s\t%s\n" "$head" "$rest"
fi
first=0
head="$line"
rest=''
fi
done
printf "%s\t%s\n" "$head" "$rest"
}
PAC=pacman
if [[ -n $(command -v pacaur) ]]; then
PAC=pacaur
fi
target=`$PAC -Ss --color=always "$@" | collapse | fzf --ansi --multi \
| awk -F'[/ ]' '{print $2}'`
if [[ -n "$target" ]]; then
$PAC -S $target
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment