Browse Source

add --help and usage functions

pull/6/head
DanielFGray 5 years ago
parent
commit
c48228a62a
3 changed files with 83 additions and 3 deletions
  1. 13
    0
      fzmp
  2. 35
    1
      ix
  3. 35
    2
      sshget

+ 13
- 0
fzmp View File

@@ -4,6 +4,17 @@ declare esc=$(printf '\033')
declare c_reset="${esc}[0m"
declare c_red="${esc}[31m"

usage() {
more <<'HELP'
fzmp [OPTIONS]

-A|--all search all songs in the library
-a|--artist search artist then filter by album
-p|--playlist search the current playlist
-h|--help print this help
HELP
}

isRunning() {
pgrep "$1" &> /dev/null
}
@@ -90,8 +101,10 @@ isRunning mpd || die 'mpd not running'
declare filter='filterAll'
while true; do
case "$1" in
-A|--all) filter='filterAll' ; shift ;;
-a|--artist) filter='filterByArtist' ; shift ;;
-p|--playlist) filter='filterByPlayist' ; shift ;;
-h|--help) usage ; exit ;;
*) break
esac
done

+ 35
- 1
ix View File

@@ -4,7 +4,38 @@ declare OPTIND
declare opts=()
declare id

set -e
usage() {
more <<'HELP'
ix [OPTIONS]

-l list all pastes, uses fzf for interactive use
-d [id] delete the paste at [id]
-i [id] replaces the paste with stdin
-h print this help
HELP
}

err() {
echo -e "${c_red}$1${c_reset}" >&2
}

die() {
exit 1
}

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

usage() {
echo TODO
@@ -37,12 +68,15 @@ listPastes() {
sed -r 's|<a href="/(\w+)">|http://ix.io/\1|'
}

has -v curl || die

hasAccount || createAccount

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

while getopts ":hld:i:n:" x; do
case "$x" in
h) usage; exit ;;
d) curl "${opts[@]}" -X DELETE "ix.io/$OPTARG"; exit ;;
l)
if [[ -z "$OPTARG" && -e ~/.netrc ]]; then

+ 35
- 2
sshget View File

@@ -4,7 +4,40 @@ declare -r fifo='/tmp/sshget.fifo'
declare -A domains=()
declare -A paths=()
declare -a files=()
declare -A requests=()

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() {
echo -e "${c_red}$1${c_reset}" >&2
}

die() {
exit 1
}

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

has -v fzf rsync || die

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

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

if (( ${#files[@]} )); then
rsync -auvzP -e ssh "${files[@]}" .

Loading…
Cancel
Save