@@ -4,7 +4,7 @@ declare -r esc=$'\033' | |||
declare -r c_reset="${esc}[0m" | |||
declare -r c_red="${esc}[31m" | |||
declare OPTIND | |||
declare opts=() | |||
declare opts=( -# ) | |||
declare id | |||
usage() { | |||
@@ -83,24 +83,31 @@ get_pastes() { | |||
grep -A1 -P '\<a href="\/[a-zA-Z0-9]+"\>' | | |||
awk -F'--' ' | |||
BEGIN {FS="<a href=\""} | |||
/a href/{sub(/\">\[r\]<\/a>/, "\t", $2); printf "http://ix.io" $2} | |||
/a href/{ sub(/\">\[r\]<\/a>/, "\t", $2); printf "http://ix.io" $2 } | |||
/@/{sub(/^\s+/, "", $0); print} | |||
' | |||
} | |||
list_pastes() { | |||
local highlighter | |||
highlighter=$(select_from 'highlight -q --force -O ansi' pygmentize) | |||
get_pastes "$(get_user_name)" | fzf \ | |||
highlighter=$(select_from 'highlight -q --force -O ansi' pygmentize cat) | |||
url=$(get_pastes "$(get_user_name)" | fzf \ | |||
--inline-info --cycle \ | |||
--header='Ctrl-E = edit; Ctrl-V = view; Ctrl-D = delete' \ | |||
--preview="p={}; curl -s \"\${p## *}\" | head -n\$LINES ${highlighter:+ | $highlighter}" \ | |||
--preview="curl -s '{1}' | ${highlighter}" \ | |||
--bind 'space:jump' \ | |||
--bind 'j:down' --bind 'k:up' \ | |||
--bind 'q:abort' \ | |||
--bind "Ctrl-V:execute:p={}; p=\"\${p## *}\"; less -R < <(curl -s \"\$p\" ${highlighter:+ | $highlighter}) > /dev/tty" \ | |||
--bind 'Ctrl-E:execute:p={}; p="${p## *}"; curl -s "$p" | vipe > /dev/tty | ix -i "${p##*/}"' \ | |||
--bind 'Ctrl-D:execute:p={}; p="${p## *}"; ix -d "${p##*/}"' | |||
--bind "Ctrl-V:execute:less -R < <(curl -s '{1}' ${highlighter:+ | $highlighter}) > /dev/tty" \ | |||
--bind 'Ctrl-E:execute:p={1}; edit=$(curl -s "$p" | vipe); ix -i "${p##*/}" <<< "$edit"' \ | |||
--expect='Ctrl-D') | |||
if [[ -n "$url" ]]; then | |||
mapfile -t res <<< "$url" | |||
if [[ "${res[0]}" = 'Ctrl-D' ]]; then | |||
ix -d "${res[1]}" | |||
list_pastes | |||
exit | |||
fi | |||
fi | |||
} | |||
has -v curl || die | |||
@@ -112,10 +119,10 @@ has_account || create_account | |||
while getopts ":hld:i:n:" x; do | |||
case "$x" in | |||
h) usage; exit ;; | |||
d) curl "${opts[@]}" -X DELETE "ix.io/$OPTARG"; exit ;; | |||
d) curl -s "${opts[@]}" -X DELETE "$OPTARG"; exit ;; | |||
l) | |||
if [[ -z "$OPTARG" && -e ~/.netrc ]]; then | |||
list_pastes | awk '{print $2}' | tee /dev/tty | xclip | |||
list_pastes | cut -d' ' -f1 | tee /dev/tty | xclip | |||
else | |||
die 'no netrc found' | |||
fi |
@@ -5,10 +5,7 @@ declare -r c_reset="${esc}[0m" | |||
declare -r c_red="${esc}[31m" | |||
declare -r c_green="${esc}[32m" | |||
declare -r c_blue="${esc}[34m" | |||
declare -a config_err | |||
declare -r config_dir="${XDG_CONFIG_DIR:-$HOME/.config}/pkgsearch" | |||
declare -r config_file="${config_dir}/conf" | |||
declare reverse | |||
declare distro | |||
declare preview_pos='right:hidden' | |||
usage() { | |||
@@ -16,12 +13,6 @@ usage() { | |||
pkgsearch [options] [query] | |||
lists and installs packages from your distro's repositories | |||
-r --reverse reverse the orientation of the layout | |||
-p --preview options for the preview window | |||
is passed directly to fzf --preview-window | |||
defaults to 'right:hidden' | |||
-h --help show this help | |||
without any arguments pkgsearch will list all available packages from your cache | |||
note: on Arch Linux you must pass a string to query the AUR | |||
HELP | |||
@@ -70,33 +61,11 @@ select_from() { | |||
fzf() { | |||
command fzf -e +s --multi --cycle --ansi \ | |||
${reverse:+--reverse} \ | |||
--bind='Ctrl-X:toggle-preview' \ | |||
--preview-window="$preview_pos" \ | |||
--no-hscroll --inline-info \ | |||
--header='tab to select multiple packages, Ctrl-X for more info on a package' "$@" | |||
} | |||
parse_config_file() { | |||
local line k v nr=0 | |||
config_err=() | |||
while IFS= read -r line; do | |||
(( ++nr )) | |||
[[ -z "$line" || "$line" = '#'* ]] && continue | |||
k="${line%% *}" | |||
v="${line#* }" | |||
if [[ -z "$v" ]]; then | |||
config_err+=( "missing value for \"$k\" in config file on line $nr" ) | |||
continue | |||
fi | |||
case "$k" in | |||
reverse) [[ "$v" = 'true' ]] && reverse="1" ;; | |||
preview) preview_pos="$v" ;; | |||
*) config_err+=( "unknown key \"$k\" in config file on line $nr" ) | |||
esac | |||
done | |||
} | |||
install() { | |||
local pkgs count | |||
mapfile -t pkgs | |||
@@ -108,9 +77,9 @@ install() { | |||
} | |||
debian() { | |||
fzf --preview='p={}; apt-cache show ${p%% *}' \ | |||
fzf --preview='apt-cache show {1}' \ | |||
--query="$1" \ | |||
< <(apt-cache search '' | sort | | |||
< <(apt-cache search '.*' | sort | | |||
sed -u -r "s|^([^ ]+)|${c_green}\1${c_reset}|") | | |||
cut -d' ' -f1 | | |||
install "sudo $(select_from 'apt' 'aptitude' 'apt-get') install" | |||
@@ -120,7 +89,7 @@ arch() { | |||
local search packages | |||
search='pacman' | |||
[[ -n "$1" ]] && search=$(select_from 'pacaur' 'yaourt' 'packer' 'apacman' 'pacman') | |||
packages=$(fzf --preview="p=\$(cut -d' ' -f2 <<< {}); $search -Si \$p" \ | |||
packages=$(fzf --preview="$search -Si {2}" \ | |||
< <( $search -Ss "$1" | | |||
gawk '{ | |||
getline descr; | |||
@@ -151,22 +120,10 @@ fedora() { | |||
install 'sudo dnf install' | |||
} | |||
[[ -s "$config_file" ]] && parse_config_file < "$config_file" | |||
while true; do | |||
case "$1" in | |||
-r|--reverse) | |||
reverse=1 | |||
shift | |||
;; | |||
-h|--help) | |||
usage | |||
exit | |||
;; | |||
-p|--preview) | |||
preview_pos="$2" | |||
shift 2 | |||
;; | |||
-h|--help) usage; exit ;; | |||
-p|--preview) preview_pos="$2"; shift 2 ;; | |||
*) break | |||
esac | |||
done | |||
@@ -174,8 +131,13 @@ done | |||
has -v fzf gawk || die | |||
request="$*" | |||
osrelease=$(awk -F'=' '"NAME" == $1 { gsub("\"", "", $2); print tolower($2); }' /etc/os-release) | |||
case "${osrelease%% *}" in | |||
if [[ -r /etc/os-release ]]; then | |||
distro=$(awk -F'=' '"NAME" == $1 { gsub("\"", "", $2); print tolower($2); }' /etc/os-release) | |||
distro="${distro%% *}" | |||
fi | |||
case "$distro" in | |||
debian|ubuntu) debian "$request" ;; | |||
arch) arch "$request" ;; | |||
void) void "$request" ;; |
@@ -25,7 +25,7 @@ HELP | |||
has() { | |||
local verbose=0 | |||
if [[ $1 == '-v' ]]; then | |||
if [[ $1 = '-v' ]]; then | |||
verbose=1 | |||
shift | |||
fi | |||
@@ -63,10 +63,10 @@ for s in "${!domains[@]}"; do | |||
ssh "${domains[$s]}" "find ${paths[$s]}" | sed -r "s|^|${domains[$s]}:|" >> "$fifo" & | |||
done | |||
mapfile -t files < <( fzf -e --inline-info --multi --cycle < "$fifo" ) | |||
mapfile -t files < <( fzf -e --inline-info --multi --cycle --bind='Ctrl-A:toggle-all,`:jump' < "$fifo" ) | |||
if (( ${#files[@]} )); then | |||
rsync -auvzP -e ssh "${files[@]}" . | |||
rsync --protect-args -auvzP -e ssh "${files[@]}" . | |||
fi | |||
cleanup |
@@ -23,13 +23,11 @@ die() { | |||
exit 1 | |||
} | |||
fzf() { | |||
command fzf --ansi --inline-info "$@" | |||
} | |||
has -v nmcli fzf || die | |||
network=$(nmcli --color yes device wifi | fzf --nth=2 --header-lines=1 | sed -r 's/^\s*\*?\s*//; s/\s*(Ad-Hoc|Infra).*//') | |||
nmcli -d wifi rescan 2> /dev/null | |||
network=$(nmcli --color yes device wifi | fzf --ansi --height=40% --reverse --cycle --inline-info --header-lines=1) | |||
[[ -z "$network" ]] && exit | |||
network=$(sed -r 's/^\s*\*?\s*//; s/\s*(Ad-Hoc|Infra).*//' <<< "$network") | |||
echo "connecting to \"${network}\"..." | |||
nmcli -a device wifi connect "$network" |