Browse Source

Merge branch 'master' of ssh://gitlab.com/DanielFGray/fzf-scripts

pull/6/head
DanielFGray 3 years ago
parent
commit
05151c4022
8 changed files with 213 additions and 196 deletions
  1. 7
    0
      README.md
  2. 42
    42
      fv
  3. 80
    75
      fzmp
  4. 18
    18
      fzmv
  5. 9
    9
      goog
  6. 21
    21
      ix
  7. 14
    14
      pkgsearch
  8. 22
    17
      sshget

+ 7
- 0
README.md View File

@@ -50,6 +50,13 @@ List and connect to wifi networks

*depends on `nmcli`*

# Install

Currently there's no installation script, but if you clone the repo you can easily symlink the scripts here with something like:

cd /path/to/repo/fzf-scripts
find -maxdepth 1 -executable -type f -exec ln -s -t $HOME/.local/bin /path/to/repo/fzf-scripts/{} \;

# Legal
Copyright (C) 2016 Daniel F Gray <DanielFGray@gmail.com>


+ 42
- 42
fv View File

@@ -1,8 +1,8 @@
#!/usr/bin/env bash

declare esc=$(printf '\033')
declare c_reset="${esc}[0m"
declare c_red="${esc}[31m"
declare -r esc=$'\033'
declare -r c_reset="${esc}[0m"
declare -r c_red="${esc}[31m"

err() {
printf "${c_red}%s${c_reset}\n" "$*" >&2
@@ -14,14 +14,14 @@ die() {
}

has() {
local verbose=false
local verbose=0
if [[ $1 == '-v' ]]; then
verbose=true
verbose=1
shift
fi
for c in "$@"; do c="${c%% *}"
for c; do c="${c%% *}"
if ! command -v "$c" &> /dev/null; then
[[ "$verbose" == true ]] && err "$c not found"
(( verbose > 0 )) && err "$c not found"
return 1
fi
done
@@ -38,7 +38,7 @@ fuzzy file filtering and command executing
HELP
}

setCmd() {
set_cmd() {
if has "$1"; then
cmd="$1"
else
@@ -48,18 +48,18 @@ setCmd() {

declare cmd='vim'
declare cmdopts=()
declare searchstr=''
declare searchcmd=''
declare searchopts=()
declare search_str=''
declare search_cmd=''
declare search_opts=()
declare allfiles=0

while getopts "hadlc:" opt; do
case "$opt" in
h) usage; exit 0 ;;
a) allfiles=1 ;;
c) setCmd "$OPTARG" ;;
c) set_cmd "$OPTARG" ;;
d) unset detach ;;
l) searchopts+=( '-l' ) ;;
l) search_opts+=( '-l' ) ;;
esac
done
shift "$((OPTIND-1))"
@@ -68,73 +68,73 @@ has -v 'fzf' || die

for c in 'ag' 'ack' 'grep'; do
if has "$c"; then
searchcmd="$c"
search_cmd="$c"
break
fi
done

if [[ $searchcmd == 'grep' ]]; then
if [[ "$search_cmd" == 'grep' ]]; then
err 'grep is slow, you should strongly consider installing ag or ack'
sleep .5
fi

if [[ -n "$1" ]]; then
if [[ -d "$1" ]]; then
searchopts+=( "$1" )
search_opts+=( "$1" )
else
searchstr="$1"
search_str="$1"
fi
shift
fi

case "$searchcmd" in
case "$search_cmd" in
'ag')
searchopts+=( '--color' )
search_opts+=( '--color' )
if [[ "$allfiles" == 1 ]]; then
searchopts+=( '-u' '--hidden' )
search_opts+=( '-u' '--hidden' )
fi
if [[ "$searchstr" == '' ]]; then
searchopts+=( '-l' )
if [[ "$search_str" == '' ]]; then
search_opts+=( '-l' )
fi
;;
'ack')
if [[ "$searchstr" == '' ]]; then
if [[ "$search_str" == '' ]]; then
if [[ "$allfiles" == 0 ]]; then
searchopts+=( '-g' '^[^\.]' )
search_opts+=( '-g' '^[^\.]' )
else
searchopts+=( '-f' )
search_opts+=( '-f' )
fi
else
searchopts+=( '-l' )
# searchopts+=( '--match' )
search_opts+=( '-l' )
# search_opts+=( '--match' )
fi
;;
'grep')
searchopts+=( '-r' '-I' )
search_opts+=( '-r' '-I' )
if [[ "$allfiles" == 0 ]]; then
searchopts+=( '--exclude-dir=bower_components' )
searchopts+=( '--exclude-dir=node_modules' )
searchopts+=( '--exclude-dir=jspm_packages' )
searchopts+=( '--exclude-dir=.cvs' )
searchopts+=( '--exclude-dir=.git' )
searchopts+=( '--exclude-dir=.hg' )
searchopts+=( '--exclude-dir=.svn' )
search_opts+=( '--exclude-dir=bower_components' )
search_opts+=( '--exclude-dir=node_modules' )
search_opts+=( '--exclude-dir=jspm_packages' )
search_opts+=( '--exclude-dir=.cvs' )
search_opts+=( '--exclude-dir=.git' )
search_opts+=( '--exclude-dir=.hg' )
search_opts+=( '--exclude-dir=.svn' )
fi
if [[ "$searchstr" == '' ]]; then
searchopts+=( '' )
if [[ "$search_str" == '' ]]; then
search_opts+=( '' )
fi
;;
esac

if [[ "$searchstr" != '' ]]; then
searchopts+=( "$searchstr" )
if [[ "$search_str" != '' ]]; then
search_opts+=( "$search_str" )
fi

choices=$($searchcmd "${searchopts[@]}" 2> /dev/null |
choices=$($search_cmd "${search_opts[@]}" 2> /dev/null |
fzf --ansi --cycle --multi) || exit 1

if [[ "$searchstr" != '' ]]; then
if [[ $searchcmd == 'ag' ]]; then
if [[ "$search_str" != '' ]]; then
if [[ $search_cmd == 'ag' ]]; then
choices=$(cut -d: -f1 <<< "$choices")
fi
fi

+ 80
- 75
fzmp View File

@@ -1,43 +1,43 @@
#!/usr/bin/env bash

declare -r esc=$(printf '\033')
declare -r esc=$'\033'
declare -r c_reset="${esc}[0m"
declare -r c_red="${esc}[31m"
declare -r config_file="${XDG_CONFIG_DIR:-$HOME/.config}/fzmp/conf"
declare default_filter='filter_all_songs'
declare track_format='[[[%artist% / ][[(%date%) ]%album% / ][[%track% - ][%title%]]]|%file%]'
declare filter='filterAllSongs'

usage() {
LESS=-FEXR less <<'HELP'
fzmp [OPTIONS]

OPTIONS:
-A --all search all songs in the library (or F1 when running)
-a --artist search artist then filter by album (or F2 when running)
-p --playlist search the current playlist (or F3 when running)
playlist view has the following keybinds:
> go to the next song in the playlist
< go to the previous song in the playlist
C-d delete the selected songs from the playlist
-h --help print this help
CONFIGURATION:
a configuration file can be defined at $XDG_CONFIG_DIR (defaults to ~/.config)
configuration options must be defined in the format of key=value
the configuration file reads the following variables:
default_view= must be 'artists' 'songs' or 'playlist'
format= a format string to be passed directly to `mpc format -f`
defaults to '[[[%artist% / ][[(%date%) ]%album% / ][[%track% - ][%title%]]]|%file%]'
for colorized output try: '[[[\e\[32m%artist%\e\[0m / ][\e\[31m[(%date%) ]%album%\e\[0m / ][\e\[34m[%track% - ][%title%]\e\[0m]]|%file%]'
fzf_options= command line options to be passed directly to fzf
changing this will override the default options: '+s -e -i --reverse --cycle'
to use the jump feature of fzf you can try '+s -e -i --reverse --cycle --bind=`:jump'
this can also be overridden with the environment variable FZMP_FZF_OPTIONS
OPTIONS:
-A --all search all songs in the library (or F1 when running)
-a --artist search artist then filter by album (or F2 when running)
-p --playlist search the current playlist (or F3 when running)
playlist view has the following keybinds:
> go to the next song in the playlist
< go to the previous song in the playlist
C-d delete the selected songs from the playlist
-h --help print this help
CONFIGURATION:
a configuration file can be defined at $XDG_CONFIG_DIR (defaults to ~/.config)
configuration options must be defined in the format of key=value
the configuration file reads the following variables:
default_view= must be 'artists' 'songs' or 'playlist'
full_song_format= a format string to be passed directly to `mpc format -f` in 'playlist' and 'all' views
defaults to '[[[%artist% / ][[(%date%) ]%album% / ][[%track% - ][%title%]]]|%file%]'
for colorized output try: '[[[\e\[32m%artist%\e\[0m / ][\e\[31m[(%date%) ]%album%\e\[0m / ][\e\[34m[%track% - ][%title%]\e\[0m]]|%file%]'
fzf_options= command line options to be passed directly to fzf
changing this will override the default options: '+s -e -i --reverse --cycle'
to use the jump feature of fzf you can try '+s -e -i --reverse --cycle --bind=`:jump'
this can also be overridden with the environment variable FZMP_FZF_OPTIONS
HELP
}

isRunning() {
is_running() {
pgrep "$1" &> /dev/null
}

@@ -51,14 +51,14 @@ die() {
}

has() {
local verbose=false
local verbose=0
if [[ $1 == '-v' ]]; then
verbose=true
verbose=1
shift
fi
for c in "$@"; do c="${c%% *}"
for c; do c="${c%% *}"
if ! command -v "$c" &> /dev/null; then
[[ "$verbose" == true ]] && err "$c not found"
(( verbose > 0 )) && err "$c not found"
return 1
fi
done
@@ -68,19 +68,19 @@ fzf() {
command fzf ${FZMP_FZF_OPTIONS:-+s -e -i --reverse --cycle} --inline-info --ansi "$@"
}

parseConfigFile() {
local default_view format fzf_options
source "$config_file" || die 'error reading configuration file'
case "$default_view" in
playlist) filter='filterPlaylist' ;;
songs) filter='filterAllSongs' ;;
artists) filter='filterByArtist' ;;
parse_config_file() {
local default_view full_song_format fzf_options
source "$config_file"
[[ -v default_view ]] && case "$default_view" in
playlist) default_filter='filter_playlist' ;;
songs) default_filter='filter_all_songs' ;;
artists) default_filter='filter_by_artist' ;;
esac
[[ -n "$format" ]] && track_format="$format"
[[ ! -v FZMP_FZF_OPTIONS && -n "$fzf_options" ]] && FZMP_FZF_OPTIONS="$fzf_options"
[[ -v full_song_format ]] && track_format="$full_song_format"
[[ ! -v FZMP_FZF_OPTIONS && -v fzf_options ]] && FZMP_FZF_OPTIONS="$fzf_options"
}

filterAllSongs() {
filter_all_songs() {
local choice
mapfile -t choice < <( mpc search -f "%file%\t$track_format" filename '' |
fzf --multi \
@@ -89,42 +89,47 @@ filterAllSongs() {
--expect='f2,f3,enter' |
cut -f1)
case "${choice[0]}" in
'f2') filterByArtist ;;
'f3') filterPlaylist ;;
'enter') printf '%s\n' "${choice[@]:1}" | playSongs ;;
'f2') filter_by_artist ;;
'f3') filter_playlist ;;
'enter') printf '%s\n' "${choice[@]:1}" | play_songs ;;
esac
}

filterByArtist() {
filter_by_artist() {
local choice
mapfile -t choice < <(mpc list artist | sort -h | fzf --expect='f1,f3,enter')
mapfile -t choice < <(mpc list artist |
sort -h |
fzf \
--preview='mpc list album artist {}' \
--expect='f1,f3,enter')
(( "${#choice[@]}" > 0 )) || die
case "${choice[0]}" in
'f1') filterAllSongs ;;
'f3') filterPlaylist ;;
'enter') filterByAlbumFromArtist "${choice[1]}" ;;
'f1') filter_all_songs ;;
'f3') filter_playlist ;;
'enter') filter_by_album_from_artist "${choice[1]}" ;;
esac
}

filterByAlbumFromArtist() {
filter_by_album_from_artist() {
local album artist choice
[[ -z "$1" ]] && filterByArtist
[[ -z "$1" ]] && filter_by_artist
artist="$1"
mapfile -t choice < <(mpc search -f '[(%date%)\t][%album%]' artist "${artist}" |
mapfile -t choice < <(mpc search -f '[(%date%)\t][%album%]' artist "$artist" |
sort -h | uniq |
fzf --prompt="$artist > " \
--preview="album=\$(cut -f2 <<< {}); mpc search -f '[[[%track% - ][%title%]]|%file%]' artist \"$artist\" album \"\$album\"" \
--expect='f1,f3,enter' \
--bind='Ctrl-A:select-all' |
cut -f2)
case "${choice[0]}" in
'f1') filterAllSongs ;;
'f3') filterPlaylist ;;
'enter') filterSongsFromAlbum "$artist" "${choice[1]}" ;;
*) filterByArtist ;;
'f1') filter_all_songs ;;
'f3') filter_playlist ;;
'enter') filter_songs_from_album "$artist" "${choice[1]}" ;;
*) filter_by_artist ;;
esac
}

filterSongsFromAlbum() {
filter_songs_from_album() {
local album artist choice
[[ -z "$1" || -z "$2" ]] && die
artist="$1"
@@ -138,14 +143,14 @@ filterSongsFromAlbum() {
--bind='Ctrl-A:select-all' |
cut -f1)
case "${choice[0]}" in
'f1') filterAllSongs ;;
'f3') filterPlaylist ;;
'enter') printf '%s\n' "${choice[@]:1}" | playSongs ;;
*) filterByAlbumFromArtist "$artist" ;;
'f1') filter_all_songs ;;
'f3') filter_playlist ;;
'enter') printf '%s\n' "${choice[@]:1}" | play_songs ;;
*) filter_by_album_from_artist "$artist" ;;
esac
}

filterPlaylist() {
filter_playlist() {
local choice
current_song=$(mpc current -f "$track_format")
mapfile -t choice < <(mpc playlist -f "%position%\t$track_format" |
@@ -157,16 +162,16 @@ filterPlaylist() {
--expect='f1,f2,>,<,ctrl-d,enter' |
cut -f1) || die
case "${choice[0]}" in
'f1') filterAllSongs ;;
'f2') filterByArtist ;;
'>') mpc -q next ; filterPlaylist ;;
'<') mpc -q prev ; filterPlaylist ;;
'ctrl-d') [[ -n "${choice[1]}" ]] && mpc -q del "${choice[@]:1}" ; filterPlaylist ;;
'enter') [[ -n "${choice[1]}" ]] && mpc -q play "${choice[@]:1}" ; filterPlaylist ;;
'f1') filter_all_songs ;;
'f2') filter_by_artist ;;
'>') mpc -q next ; filter_playlist ;;
'<') mpc -q prev ; filter_playlist ;;
'ctrl-d') [[ -n "${choice[1]}" ]] && mpc -q del "${choice[@]:1}" ; filter_playlist ;;
'enter') [[ -n "${choice[1]}" ]] && mpc -q play "${choice[@]:1}" ; filter_playlist ;;
esac
}

playSongs() {
play_songs() {
mapfile -t songs
(( "${#songs[@]}" > 0 )) || die
printf '%s\n' "${songs[@]}" | mpc -q add
@@ -174,22 +179,22 @@ playSongs() {
(( ${#songs[@]} > 1 )) &&
index=$(( index - ${#songs[@]} + 1))
mpc -q play "$index"
filterPlaylist
filter_playlist
}

[[ -s "$config_file" ]] && parseConfigFile
[[ -s "$config_file" ]] && parse_config_file

while :; do
case "$1" in
-A|--all) filter='filterAllSongs' ; shift ;;
-a|--artist) filter='filterByArtist' ; shift ;;
-p|--playlist) filter='filterPlaylist' ; shift ;;
-A|--all) default_filter='filter_all_songs' ; shift ;;
-a|--artist) default_filter='filter_by_artist' ; shift ;;
-p|--playlist) default_filter='filter_playlist' ; shift ;;
-h|--help) usage ; exit ;;
*) break
esac
done

has -v fzf mpc || die
isRunning mpd || [[ -n "$MPD_HOST" ]] || die "can't connect to mpd"
is_running mpd || [[ -v MPD_HOST ]] || die "can't connect to mpd"

$filter
$default_filter

+ 18
- 18
fzmv View File

@@ -1,8 +1,8 @@
#!/usr/bin/env bash

declare esc=$(printf '\033')
declare c_reset="${esc}[0m"
declare c_red="${esc}[31m"
declare -r esc=$'\033'
declare -r c_reset="${esc}[0m"
declare -r c_red="${esc}[31m"
declare dryrun verbose

set -e
@@ -16,14 +16,14 @@ die() {
}

has() {
local verbose=false
local verbose=0
if [[ $1 == '-v' ]]; then
verbose=true
verbose=1
shift
fi
for c in "$@"; do c="${c%% *}"
for c; do c="${c%% *}"
if ! command -v "$c" &> /dev/null; then
[[ "$verbose" == true ]] && err "$c not found"
(( verbose > 0 )) && err "$c not found"
return 1
fi
done
@@ -53,25 +53,25 @@ pick_files() {
}

pick_destination() {
local cwd browsedir browseinfo query dirs
local cwd browse_dir browse_info query dirs
cwd=$(pwd)
while [[ "$browsedir" != "$cwd" ]]; do
while [[ "$browse_dir" != "$cwd" ]]; do
dirs=$( (echo '..'; find -maxdepth 1 -type d 2> /dev/null ) |
sed 's|./||' |
sort -h)
mapfile -t browseinfo < <(
mapfile -t browse_info < <(
fzf --print-query \
--history="${HOME}/.cache/fzmv_history" \
--header="${errors:-move files here}" <<< "$dirs")
query=${browseinfo[0]}
browsedir=${browseinfo[1]}
[[ -d "$query" ]] && browsedir="$query"
[[ ! -d "$browsedir" ]] && return 1
if [[ "$browsedir" == '.' && $(realpath "$browsedir") != "$cwd" ]]; then
realpath "$browsedir"
query=${browse_info[0]}
browse_dir=${browse_info[1]}
[[ -d "$query" ]] && browse_dir="$query"
[[ ! -d "$browse_dir" ]] && return 1
if [[ "$browse_dir" == '.' && $(realpath "$browse_dir") != "$cwd" ]]; then
realpath "$browse_dir"
break
else
cd "$browsedir" || die
cd "$browse_dir" || die
continue
fi
done
@@ -80,7 +80,7 @@ pick_destination() {
while (( $# > 0 )); do
case $1 in
-t|--test) dryrun=true ;;
-v|--verbose) verbose=true ;;
-v|--verbose) verbose=1 ;;
esac
shift
done

+ 9
- 9
goog View File

@@ -1,8 +1,8 @@
#!/usr/bin/env bash

declare esc=$(printf '\033')
declare c_reset="${esc}[0m"
declare c_red="${esc}[31m"
declare -r esc=$'\033'
declare -r c_reset="${esc}[0m"
declare -r c_red="${esc}[31m"

err() {
printf "${c_red}%s${c_reset}\n" "$*" >&2
@@ -14,14 +14,14 @@ die() {
}

has() {
local verbose=false
local verbose=0
if [[ $1 == '-v' ]]; then
verbose=true
verbose=1
shift
fi
for c in "$@"; do c="${c%% *}"
for c; do c="${c%% *}"
if ! command -v "$c" &> /dev/null; then
[[ "$verbose" == true ]] && err "$c not found"
(( verbose > 0 )) && err "$c not found"
return 1
fi
done
@@ -32,10 +32,10 @@ openurl() {
local browser
case "$url" in
*youtube.com*|*youtu.be*|*vimeo.com*)
browser=$(select-from \
browser=$(select_from \
mpv mplayer2 mplayer) ;;
*)
browser=$(select-from \
browser=$(select_from \
-c "pgrep -u $USER -i" \
firefox chromium-browser chrome)
[[ ! $browser ]] && browser='w3m'

+ 21
- 21
ix View File

@@ -1,14 +1,14 @@
#!/usr/bin/env bash

declare esc=$(printf '\033')
declare c_reset="${esc}[0m"
declare c_red="${esc}[31m"
declare -r esc=$'\033'
declare -r c_reset="${esc}[0m"
declare -r c_red="${esc}[31m"
declare OPTIND
declare opts=()
declare id

usage() {
more <<'HELP'
LESS=-FEXR less <<'HELP'
ix [OPTIONS]

-l list all pastes, uses fzf for interactive use
@@ -27,22 +27,22 @@ die() {
}

has() {
local verbose=false
local verbose=0
if [[ $1 == '-v' ]]; then
verbose=true
verbose=1
shift
fi
for c in "$@"; do c="${c%% *}"
for c; do c="${c%% *}"
if ! command -v "$c" &> /dev/null; then
[[ "$verbose" == true ]] && err "$c not found"
(( verbose > 0 )) && err "$c not found"
return 1
fi
done
}

select-from() {
select_from() {
local cmd='command -v'
for a in "$@"; do
for a; do
case "$a" in
-c)
cmd="$2"
@@ -50,7 +50,7 @@ select-from() {
;;
esac
done
for c in "$@"; do
for c; do
if $cmd "${c%% *}" &> /dev/null; then
echo "$c"
return 0
@@ -59,11 +59,11 @@ select-from() {
return 1
}

hasAccount() {
has_account() {
grep -qF 'ix.io' ~/.netrc
}

createAccount() {
create_account() {
echo "It seems you don't have a ~/.netrc with ix.io in it. Let's make one!"
read -r -p 'enter a username: ' username
read -rs -p 'enter a password (this will be hashed with sha256sum): ' password
@@ -74,11 +74,11 @@ createAccount() {
echo "$username"
}

getUserName() {
get_user_name() {
awk '"ix.io"==$2{print $4}' ~/.netrc
}

getPastes() {
get_pastes() {
curl -s "http://ix.io/user/$1" |
grep -A1 -P '\<a href="\/[a-zA-Z0-9]+"\>' |
awk -F'--' '
@@ -88,13 +88,13 @@ getPastes() {
'
}

listPastes() {
list_pastes() {
local highlighter
highlighter=$(select-from pygmentize 'highlight -q --force -O ansi')
getPastes "$(getUserName)" | fzf \
highlighter=$(select_from 'highlight -q --force -O ansi' pygmentize)
get_pastes "$(get_user_name)" | fzf \
--inline-info --cycle \
--header='Ctrl-E = edit; Ctrl-V = view; Ctrl-D = delete' \
--preview="p={}; curl -s \"\${p## *}\" ${highlighter:+ | $highlighter}" \
--preview="p={}; curl -s \"\${p## *}\" | head -n\$LINES ${highlighter:+ | $highlighter}" \
--bind 'space:jump' \
--bind 'j:down' --bind 'k:up' \
--bind 'q:abort' \
@@ -105,7 +105,7 @@ listPastes() {

has -v curl || die

hasAccount || createAccount
has_account || create_account

[[ -e ~/.netrc ]] && opts+=( '-n' )

@@ -115,7 +115,7 @@ while getopts ":hld:i:n:" x; do
d) curl "${opts[@]}" -X DELETE "ix.io/$OPTARG"; exit ;;
l)
if [[ -z "$OPTARG" && -e ~/.netrc ]]; then
listPastes | awk '{print $2}' | tee /dev/tty | xclip
list_pastes | awk '{print $2}' | tee /dev/tty | xclip
else
die 'no netrc found'
fi

+ 14
- 14
pkgsearch View File

@@ -1,10 +1,10 @@
#!/usr/bin/env bash

declare esc=$(printf '\033')
declare c_reset="${esc}[0m"
declare c_red="${esc}[31m"
declare c_green="${esc}[32m"
declare c_blue="${esc}[34m"
declare -r esc=$'\033'
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 reverse

usage() {
@@ -29,22 +29,22 @@ die() {
}

has() {
local verbose=false
local verbose=0
if [[ $1 == '-v' ]]; then
verbose=true
verbose=1
shift
fi
for c in "$@"; do c="${c%% *}"
for c; do c="${c%% *}"
if ! command -v "$c" &> /dev/null; then
[[ "$verbose" == true ]] && err "$c not found"
(( "$verbose" > 0 )) && err "$c not found"
return 1
fi
done
}

select-from() {
select_from() {
local cmd='command -v'
for a in "$@"; do
for a; do
case "$a" in
-c)
cmd="$2"
@@ -52,7 +52,7 @@ select-from() {
;;
esac
done
for c in "$@"; do
for c; do
if $cmd "${c%% *}" &> /dev/null; then
echo "$c"
return 0
@@ -74,7 +74,7 @@ install() {
(( ${#pkgs} > 0 )) || exit
count="${#pkgs[@]} package"
(( ${#pkgs[@]} > 1 )) && count+='s'
echo "installing ${count}: ${pkgs[*]}"
printf "installing %s: %s\n" "$count" "${pkgs[*]}"
$1 "${pkgs[@]}" < /dev/tty
}

@@ -86,7 +86,7 @@ debian() {
< <(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"
install "sudo $(select_from 'apt' 'aptitude' 'apt-get') install"
}

arch() {

+ 22
- 17
sshget View File

@@ -1,20 +1,14 @@
#!/usr/bin/env bash

declare -r esc=$'\033'
declare -r c_reset="${esc}[0m"
declare -r c_red="${esc}[31m"

declare -r fifo='/tmp/sshget.fifo'
declare -A domains=()
declare -A paths=()
declare -a files=()

declare esc=$(printf '\033')
declare c_reset="${esc}[0m"
declare c_red="${esc}[31m"

usage() {
more <<'HELP'
sshget user@host1:/path/to/search user@host2:/path/to/search
HELP
}

err() {
printf "${c_red}%s${c_reset}\n" "$*" >&2
}
@@ -23,15 +17,21 @@ die() {
exit 1
}

usage() {
LESS=-FEXR less <<'HELP'
sshget <user@host1:/path/to/search ...>
HELP
}

has() {
local verbose=false
local verbose=0
if [[ $1 == '-v' ]]; then
verbose=true
verbose=1
shift
fi
for c in "$@"; do c="${c%% *}"
for c; do c="${c%% *}"
if ! command -v "$c" &> /dev/null; then
[[ "$verbose" == true ]] && err "$c not found"
(( verbose > 0 )) && err "$c not found"
return 1
fi
done
@@ -46,8 +46,13 @@ trap cleanup SIGHUP SIGINT SIGTERM

mkfifo "$fifo"

for a in "$@"; do
host="${a%%:*}"
if (( $# < 1 )); then
usage
die
fi

for a; do
host="${a%:*}"
path="${a##*:}"
domains+=( ["$a"]="$host" )
paths+=( ["$a"]="$path" )
@@ -55,7 +60,7 @@ for a in "$@"; do
done

for s in "${!domains[@]}"; do
ssh "${domains[$s]}" "find ${paths[$s]}" | sed -r "s|^(.*)|${domains[$s]}:\"\1\"|" >> "$fifo" &
ssh "${domains[$s]}" "find ${paths[$s]}" | sed -r "s|^|${domains[$s]}:|" >> "$fifo" &
done

mapfile -t files < <( fzf -e --inline-info --multi --cycle < "$fifo" )

Loading…
Cancel
Save