Skip to content

Commit

Permalink
automatically search for second argument in fzf's list. now commands …
Browse files Browse the repository at this point in the history
…such as 'pacli i canta' or 'pacli -i canta' or 'pacli --i canta' are much more intuitive
  • Loading branch information
excalibur1234 committed Aug 31, 2016
1 parent bc30de6 commit 894662f
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions pacli
Expand Up @@ -71,13 +71,13 @@ function func_i
{
# the "package-query -Sl -f '%n %v - %d' " displays a list of all packages from the Manjaro repositories and formats them like "NAME VERSION - DESCRIPTION". the first part (="NAME") gets (printed and) saved to the "pkg" variable.
local pkg
pkg=$(package-query -Sl -f "%n %v - %d" | sort | fzf -m -e +s -i -0 --cycle --reverse --margin=4%,1%,1%,2% --inline-info --header="Press TAB to (un)select. Press ENTER to install. Press ESC or CTRL+C to quit." --prompt='Enter string to filter displayed list of packages > ' | awk '{print $1}' )
pkg=$(package-query -Sl -f "%n %v - %d" | sort | fzf -m -e +s -i -0 --query="$input2" --cycle --reverse --margin=4%,1%,1%,2% --inline-info --header="Press TAB to (un)select. Press ENTER to install. Press ESC or CTRL+C to quit." --prompt='Enter string to filter displayed list of packages > ' | awk '{print $1}' )

# only run the command inside the if-statement, if $pkg variable is not empty - this happens when fzf is quit with ESC or CTRL+C
if [[ -n $pkg ]]
then
sudo pacman -S $pkg --color always
fi
fi
}


Expand All @@ -87,8 +87,8 @@ function func_r
# takes a package list from "pacman -Qq", then sorts it alphabetically, then make the resulting list available to fzf.
# fzf lets you search and select the given list in a fast way. the "-m" flags makes it possible to select multiple list items.
local pkg
pkg=$(package-query -Q -f "%n %v - %d" | sort | fzf -m -e +s -i -0 --cycle --reverse --margin=4%,1%,1%,2% --inline-info --header="Press TAB to (un)select. Press ENTER to remove. Press ESC or CTRL+C to quit." --prompt='Enter string to filter displayed list of packages > ' | awk '{print $1}' )

pkg=$(package-query -Q -f "%n %v - %d" | sort | fzf -m -e +s -i -0 --query="$input2" --cycle --reverse --margin=4%,1%,1%,2% --inline-info --header="Press TAB to (un)select. Press ENTER to remove. Press ESC or CTRL+C to quit." --prompt='Enter string to filter displayed list of packages > ' | awk '{print $1}' )
if [[ -n $pkg ]]
then
sudo pacman -Rsn $pkg --color always
Expand All @@ -108,7 +108,7 @@ function func_info

# the following command lets you search through the file "/tmp/pacli-packages" with fzf and save your selection in "pkg"
local pkg
pkg=$(sort /tmp/pacli-packages | fzf -e +s -i -0 --cycle --reverse --margin=4%,1%,1%,2% --inline-info --header="Press ENTER to display info. Press ESC or CTRL+C to quit." --prompt='Enter string to filter displayed list of packages > ')
pkg=$(sort /tmp/pacli-packages | fzf -e +s -i -0 --query="$input2" --cycle --reverse --margin=4%,1%,1%,2% --inline-info --header="Press ENTER to display info. Press ESC or CTRL+C to quit." --prompt='Enter string to filter displayed list of packages > ')

# only run the command inside the if-statement, if $pkg variable is not empty - this happens when fzf is quit with ESC or CTRL+C
if [[ -n $pkg ]]
Expand All @@ -128,12 +128,12 @@ function func_l
{
# use fzf to ask the user to select an installed package. the package name gets save in variable "pkg"
local pkg
pkg=$(pacman -Qq | fzf -e +s -i -0 --cycle --reverse --margin=4%,1%,1%,2% --inline-info --header="Press ENTER to list files. Press ESC or CTRL+C to quit." --prompt='Enter string to filter displayed list of packages > ')
pkg=$(pacman -Qq | fzf -e +s -i -0 --query="$input2" --cycle --reverse --margin=4%,1%,1%,2% --inline-info --header="Press ENTER to list files. Press ESC or CTRL+C to quit." --prompt='Enter string to filter displayed list of packages > ')

if [[ -n $pkg ]]
then
# take the output of command "pacman -Qlq $pkg" and make it searchable with fzf. for all used fzf flags see "man fzf". store all marked lines in file /tmp/pacli-list.
pacman -Qlq $pkg --color always | fzf -m -e +s -i -q /usr/bin/ --reverse --margin=4%,1%,1%,1% --inline-info --header="List of files of package \"${pkg}\". Press ESC or CTRL+C to quit." --prompt='Enter string to filter displayed directories and files > ' >> /tmp/pacli-list
pacman -Qlq $pkg --color always | fzf -m -e +s -i --query="/usr/bin/" --reverse --margin=4%,1%,1%,1% --inline-info --header="List of files of package \"${pkg}\". Press ESC or CTRL+C to quit." --prompt='Enter string to filter displayed directories and files > ' >> /tmp/pacli-list
fi
}

Expand All @@ -145,7 +145,7 @@ function func_t
pacman -Qq >> /tmp/pacli-packages-local

local pkg
pkg=$(sort /tmp/pacli-packages-local | fzf -e +s -i -0 --cycle --reverse --margin=4%,1%,1%,2% --inline-info --header="Press ENTER to show tree. Press ESC or CTRL+C to quit." --prompt='Enter string to filter displayed list of packages > ')
pkg=$(sort /tmp/pacli-packages-local | fzf -e +s -i -0 --query="$input2" --cycle --reverse --margin=4%,1%,1%,2% --inline-info --header="Press ENTER to show tree. Press ESC or CTRL+C to quit." --prompt='Enter string to filter displayed list of packages > ')

# look in func_info for explanations
if [[ -n $pkg ]]
Expand All @@ -163,7 +163,7 @@ function func_t
function func_rt
{
local pkg
pkg=$(pacman -Qq | fzf -e +s -i -0 --cycle --reverse --margin=4%,1%,1%,2% --inline-info --header="Press ENTER to show reverse tree. Press ESC or CTRL+C to quit." --prompt='Enter string to filter displayed list of packages > ')
pkg=$(pacman -Qq | fzf -e +s -i -0 --query="$input2" --cycle --reverse --margin=4%,1%,1%,2% --inline-info --header="Press ENTER to show reverse tree. Press ESC or CTRL+C to quit." --prompt='Enter string to filter displayed list of packages > ')

pactree -c -r $pkg
}
Expand All @@ -174,7 +174,7 @@ function func_rt

function func_log
{
tail -5000 /var/log/pacman.log | fzf -m -e +s -i -0 -q alpm --tac --reverse --margin=4%,1%,1%,1% --inline-info --header="Navigate with PageUp / PageDown Keys. Press ESC or CTRL+C to quit." --prompt='Enter string to filter displayed logs > ' >> /tmp/pacli-log
tail -5000 /var/log/pacman.log | fzf -m -e +s -i -0 --query="ALPM] " --tac --reverse --margin=4%,1%,1%,1% --inline-info --header="Navigate with PageUp / PageDown Keys. Press ESC or CTRL+C to quit." --prompt='Enter string to filter displayed logs > ' >> /tmp/pacli-log
}


Expand All @@ -184,7 +184,7 @@ function func_d
pacman -Qq >> /tmp/pacli-packages-local

local pkg
pkg=$(sort /tmp/pacli-packages-local | fzf -e +s -i -0 --cycle --reverse --margin=4%,1%,1%,2% --inline-info --header="Press ENTER to downgrade. Press ESC or CTRL+C to quit." --prompt='Enter string to filter displayed list of packages > ')
pkg=$(sort /tmp/pacli-packages-local | fzf -e +s -i -0 --query="$input2" --cycle --reverse --margin=4%,1%,1%,2% --inline-info --header="Press ENTER to downgrade. Press ESC or CTRL+C to quit." --prompt='Enter string to filter displayed list of packages > ')

downgrade $pkg
}
Expand Down Expand Up @@ -292,7 +292,7 @@ function func_empty
function func_fi
{
local pkg
pkg=$(package-query -Sl -f "%n %v - %d" | sort | fzf -m -e +s -i -0 --cycle --reverse --margin=4%,1%,1%,2% --inline-info --header="Press TAB to (un)select. Press ENTER to install. Press ESC or CTRL+C to quit." --prompt='Enter string to filter displayed list of packages > ' | awk '{print $1}' )
pkg=$(package-query -Sl -f "%n %v - %d" | sort | fzf -m -e +s -i -0 --query="$input2" --cycle --reverse --margin=4%,1%,1%,2% --inline-info --header="Press TAB to (un)select. Press ENTER to install. Press ESC or CTRL+C to quit." --prompt='Enter string to filter displayed list of packages > ' | awk '{print $1}' )

if [[ -n $pkg ]]
then
Expand All @@ -304,7 +304,7 @@ function func_fi
function func_fr
{
local pkg
pkg=$(package-query -Q -f "%n %v - %d" | fzf -m -e +s -i -0 --cycle --reverse --margin=4%,1%,1%,2% --inline-info --header="Press TAB to (un)select. Press ENTER to remove. Press ESC or CTRL+C to quit." --prompt='Enter string to filter displayed list of packages > ' | awk '{print $1}' )
pkg=$(package-query -Q -f "%n %v - %d" | fzf -m -e +s -i -0 --query="$input2" --cycle --reverse --margin=4%,1%,1%,2% --inline-info --header="Press TAB to (un)select. Press ENTER to remove. Press ESC or CTRL+C to quit." --prompt='Enter string to filter displayed list of packages > ' | awk '{print $1}' )

if [[ -n $pkg ]]
then
Expand Down Expand Up @@ -345,7 +345,7 @@ function func_ia

local pkg

pkg=$(sort /tmp/pacli-packages | fzf -m -e +s -i -0 --cycle --reverse --margin=4%,1%,1%,2% --inline-info --header="Press TAB to (un)select. Press ENTER to install. Press ESC or CTRL+C to quit." --prompt='Enter string to filter displayed list of packages > ')
pkg=$(sort /tmp/pacli-packages | fzf -m -e +s -i -0 --query="$input2" --cycle --reverse --margin=4%,1%,1%,2% --inline-info --header="Press TAB to (un)select. Press ENTER to install. Press ESC or CTRL+C to quit." --prompt='Enter string to filter displayed list of packages > ')

if [[ -n $pkg ]]
then
Expand Down Expand Up @@ -599,8 +599,11 @@ To exit this Help Page, press "q".



# write argument of "pacli $1" to "input" variable
# write first argument of "pacli ..." to "input" variable.
input=$1
# wirte all other arguments of "pacli $1 ..." to "input2" variable. all arguments gets combined into one variable with spaces, but no breaks.
#fzf will always display search results for "input2", if it exists (and "input" is a valid function"). if "input2" is not found in fzf's list, NOTHING is displayed.
input2=${*:2}

# if "input" starts with a "-" or "--" symbol, the "-" symbol(s) gets removed from the beginnig of "input" variable
input=${input#-}
Expand All @@ -623,6 +626,7 @@ then
fi

unset input
unset input2



Expand Down

0 comments on commit 894662f

Please sign in to comment.