Last active
September 29, 2017 10:07
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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