Skip to content

Commit

Permalink
added bash_completion
Browse files Browse the repository at this point in the history
  • Loading branch information
bozso committed Oct 4, 2019
1 parent 8d64221 commit dbf2e35
Show file tree
Hide file tree
Showing 5 changed files with 349 additions and 39 deletions.
281 changes: 281 additions & 0 deletions bash_completion/tsv-utils
Original file line number Diff line number Diff line change
@@ -0,0 +1,281 @@
# bash completion for eBay's TSV Utility command line tools.
#
# Copyright (c) 2017-2019, eBay Software Foundation
# Initially written by Jon Degenhardt
#
# License: Boost Licence 1.0 (http://boost.org/LICENSE_1_0.txt)
#
# -------------------------------------------------------------
#
# This file enables option completion for the command line tools. For
# information bash completions and how to install them, see:
# https://github.com/scop/bash-completion
# https://debian-administration.org/article/316/An_introduction_to_bash_completion_part_1
#
# Mac users may benefit from setup instructions at:
# https://trac.macports.org/wiki/howto/bash-completion
# http://davidalger.com/development/bash-completion-on-os-x-with-brew/
#

_csv2tsv()
{
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="--help --help-verbose --version --header --quote --csv-delim --tsv-delim --replacement"

# Options requiring an argument or precluding other options
case $prev in
-h|--help|--help-verbose|-V|--version|-q|--quote|-c|--csv-delim|-t|--tsv-delim|-r|--replacement)
return
;;
esac

if [[ ${cur} == -* ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
fi

compopt -o filenames
COMPREPLY=( $(compgen -f -X "$xspec" -- ${cur}) $( compgen -d -- "$cur" ) )
}
complete -F _csv2tsv csv2tsv

_number_lines()
{
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="--help --version --header --header-string --start-number --delimiter"

# Options requiring an argument or precluding other options
case $prev in
-h|--help|-V|--version|-s|--header-string|-n|--start-number|-d|--delimiter)
return
;;
esac

if [[ ${cur} == -* ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
fi

compopt -o filenames
COMPREPLY=( $(compgen -f -X "$xspec" -- ${cur}) $( compgen -d -- "$cur" ) )
}
complete -F _number_lines number-lines

_tsv_append()
{
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="--help --help-verbose --version --header --track-source --source-header --file --delimiter"

# Options requiring an argument or precluding other options
case $prev in
-h|--help|--help-verbose|-V|--version|-s|--source-header|-f|--file|-d|--delimiter)
return
;;
esac

if [[ ${cur} == -* ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
fi

compopt -o filenames
COMPREPLY=( $(compgen -f -X "$xspec" -- ${cur}) $( compgen -d -- "$cur" ) )
}
complete -F _tsv_append tsv-append

_tsv_filter()
{
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="--help --help-verbose --help-options --version --header --or --invert --delimiter --empty --not-empty --blank --not-blank --is-numeric --is-finite --is-nan --is-infinity --le --lt --ge --gt --eq --ne --str-le --str-lt --str-ge --str-gt --str-eq --istr-eq --str-ne --istr-ne --str-in-fld --istr-in-fld --str-not-in-fld --istr-not-in-fld --regex --iregex --not-regex --not-iregex --ff-le --ff-lt --ff-ge --ff-gt --ff-eq --ff-ne --ff-str-eq --ff-istr-eq --ff-str-ne --ff-istr-ne --ff-absdiff-le --ff-absdiff-gt ff-reldiff-le --ff-reldiff-gt"

# Options requiring an argument or precluding other options
case $prev in
-h|--help|--help-verbose|--help-options|-V|--version|-d|--delimiter|--le|--lt|--ge|--gt|--eq|--ne|--str-le|--str-lt|--str-ge|--str-gt|--str-eq|--istr-eq|--str-ne|--istr-ne|--str-in-fld|--istr-in-fld|--str-not-in-fld|--istr-not-in-fld|--regex|--iregex|--not-regex|--not-iregex|--ff-le|--ff-lt|--ff-ge|--ff-gt|--ff-eq|--ff-ne|--ff-str-eq|--ff-istr-eq|--ff-str-ne|--ff-istr-ne|--ff-absdiff-le|--ff-absdiff-gt|ff-reldiff-le|--ff-reldiff-gt)

return
;;
esac

if [[ ${cur} == -* ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
fi

compopt -o filenames
COMPREPLY=( $(compgen -f -X "$xspec" -- ${cur}) $( compgen -d -- "$cur" ) )
}
complete -F _tsv_filter tsv-filter

_tsv_join()
{
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="--help --help-verbose --version --filter-file --key-fields --data-fields --append-fields --header --prefix --write-all --exclude --delimiter --allow-duplicate-keys"

# Options requiring an argument or precluding other options
# Options requiring a filename argument are handled in their own case match, ie. -f|--filter-file
case $prev in
-h|--help|--help-verbose|-V|--version|-k|--key-fields|-d|--data-fields|-a|--append-fields|-p|--prefix|-w|--write-all|--delimiter)
return
;;

-f|--filter-file)
compopt -o filenames
COMPREPLY=( $(compgen -f -X "$xspec" -- ${cur}) $( compgen -d -- "$cur" ) )
return 0
;;
esac

if [[ ${cur} == -* ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
fi

compopt -o filenames
COMPREPLY=( $(compgen -f -X "$xspec" -- ${cur}) $( compgen -d -- "$cur" ) )
}
complete -F _tsv_join tsv-join

_tsv_pretty()
{
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="--help --help-verbose --version --header --no-header --lookahead --repeat-header --underline-header --format-floats --precision --replace-empty --empty-replacement --delimiter --space-between-fields --max-text-width --auto-preamble --preamble"

# Options requiring an argument or precluding other options
case $prev in
-h--help|--help-verbose|-V|--version|-l|--lookahead|-r|--repeat-header|-p|--precision|-E|--empty-replacement|-d|--delimiter|-s|--space-between-fields|-m|--max-text-width|-b|--preamble)
return
;;
esac

if [[ ${cur} == -* ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
fi

compopt -o filenames
COMPREPLY=( $(compgen -f -X "$xspec" -- ${cur}) $( compgen -d -- "$cur" ) )
}
complete -F _tsv_pretty tsv-pretty

_tsv_sample()
{
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="--help --help-verbose --version --header --num --prob --weight-field --key-fields --replace --inorder --print-random --gen-random-inorder --compatibility-mode --static-seed --seed-value --delimiter --prefer-skip-sampling --prefer-algorithm-r"

# Options requiring an argument or precluding other options
case $prev in
-h|--help|--help-verbose|-V|--version|-n|--num|-p|--prob|-w|--weight-field|-k|--key-fields|-r|--replace|-v|--seed-value|-d|--delimiter|--prefer-skip-sampling|--prefer-algorithm-r)
return
;;
esac

if [[ ${cur} == -* ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
fi

compopt -o filenames
COMPREPLY=( $(compgen -f -X "$xspec" -- ${cur}) $( compgen -d -- "$cur" ) )
}
complete -F _tsv_sample tsv-sample

_tsv_select()
{
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="--help --version --header --fields --rest --delimiter"

# Options requiring an argument or precluding other options
# Options with a restricted set of arguments (ie. -r|--rest) have their own case clause.
case $prev in
-h|--help|-V|--version|-f|--fields|-d|--delimiter)
return
;;
-r|--rest)
COMPREPLY=( $(compgen -W "none first last" -- ${cur}) )
return
;;
esac

if [[ ${cur} == -* ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
fi

compopt -o filenames
COMPREPLY=( $(compgen -f -X "$xspec" -- ${cur}) $( compgen -d -- "$cur" ) )
}
complete -F _tsv_select tsv-select

_tsv_summarize()
{
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="--help --help-verbose --version --group-by --header --write-header --delimiter --values-delimiter --float-precision --exclude-missing --replace-missing --count --count-header --retain --first --last --min --max --range --sum --mean --median --quantile --mad --var --stdev --mode --mode-count --unique-count --missing-count --not-missing-count --values --unique-values"

# Options requiring an argument or precluding other options
case $prev in
-h|--help|--help-verbose|-V|--version|-g|--group-by|-d|--delimiter|-v|--values-delimiter|-p|--float-precision|-x|--exclude-missing|-r|--replace-missing|--count-header|--retain|--first|--last|--min|--max|--range|--sum|--mean|--median|--quantile|--mad|--var|--stdev|--mode|--mode-count|--unique-count|--missing-count|--not-missing-count|--values|--unique-values)
return
;;
esac

if [[ ${cur} == -* ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
fi

compopt -o filenames
COMPREPLY=( $(compgen -f -X "$xspec" -- ${cur}) $( compgen -d -- "$cur" ) )
}
complete -F _tsv_summarize tsv-summarize

_tsv_uniq()
{
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="--help --help-verbose --version --header --fields --ignore-case --repeated --at-least --max --number --equiv --equiv-header --equiv-start --delimiter"

# Options requiring an argument or precluding other options
case $prev in
-h|--help|--help-verbose|-V|--version|-f|--fields|-a|--at-least|-m|--max|--equiv-header|--equiv-start|-d|--delimiter)
return
;;
esac

if [[ ${cur} == -* ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
fi

compopt -o filenames
COMPREPLY=( $(compgen -f -X "$xspec" -- ${cur}) $( compgen -d -- "$cur" ) )
}
complete -F _tsv_uniq tsv-uniq
5 changes: 1 addition & 4 deletions configs/openbox/lxde-rc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -301,16 +301,13 @@
<keybind key="W-r">
<action name="Execute">
<command>openbox --reconfigure</command>
<command>killall -SIGUSR1 tint2</command>
</action>
</keybind>
<!--
<keybind key="W-i">
<action name="Execute">
<command>parole</command>
<command>sh /home/istvan/progs/utils/menu.sh import</command>
</action>
</keybind>
-->
<keybind key="W-w">
<action name="Execute">
<command>chromium-browser</command>
Expand Down
28 changes: 25 additions & 3 deletions menu.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#!/usr/bin/env bash
#! /usr/bin/env sh

progs="$HOME/progs"
progs="${HOME}/progs"
icons="$progs/utils/icons"


set -e

opt="-fn -adobe-helvetica-bold-r-normal-*-25-180-100-100-p-138-iso8859-1"
Expand Down Expand Up @@ -209,6 +207,27 @@ select_module() {
done
}

Basename() {
while IFS= read -r line; do
printf '%s\n' "$(basename $line .png)"
done
}

import() {
local root="${HOME}/screencap"
mkdir -p "${root}"

last="$(ls ${root}/img_*.png \
| Basename \
| tr -d '[:alpha:]' \
| tr -d '_' \
| sort -g \
| tail -1)"

new=$((last+1))

import "${root}/img_${new}.png" > "${HOME}/import.log"
}

main() {
check_narg $# 1
Expand All @@ -226,6 +245,9 @@ main() {
"shutdown")
shutdown_now
;;
"import")
import
;;
*)
printf "Unrecognized option %s!\n" $1 >&2
return 1
Expand Down
Loading

0 comments on commit dbf2e35

Please sign in to comment.