Synopsis

I want to be able to start a search from the command line. This will be faster than remembering the obscure bindings for both terminal user interfaces.

Demonstration

htop

asciinema recording

termshark

asciinema recording

Code

htop

The last parameter will be considered to be a search filter, if it is doesn’t look like an option.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
#!/bin/bash
export TTY

( hs "$(basename "$0")" "$@" "#" "<==" "$(ps -o comm= $PPID)" 0</dev/null ) &>/dev/null

last_arg="${@: -1}"

if test "$#" -gt 0 && ! [[ "$last_arg" == -* ]]; then
    query="$*"
    shift "$#"
fi

CMD="$(cmd "$@")"
: ${CMD:="$(cmd "$@")"}

if test -n "$query"; then
    x -sh "/usr/local/bin/htop $CMD" -f4 -s "$query" -c m -i
else
    /usr/local/bin/htop "$@"
fi

termshark

The last parameter will be considered to be a search filter, if it starts with a forward slash.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/bin/bash
export TTY

( hs "$(basename "$0")" "$@" "#" "<==" "$(ps -o comm= $PPID)" 0</dev/null ) &>/dev/null

if test "$TERM" = "eterm-256color"; then
    export TERM=screen-256color
fi

last_arg="${@: -1}"
case "$last_arg" in
    /*) {
        test "$#" -gt 0 && set -- "${@:1:$(($#-1))}" # shift last arg
        CMD="$(cmd "$@")"
        : ${CMD:="$(cmd "$@")"}
        x -shE "${GOPATH%%:*}/bin/termshark $CMD" -e Filter -s "$last_arg" -sl 3 -c m -c i -i
        exit $?
    }
    ;;

    *)
esac

${GOPATH%%:*}/bin/termshark "$@"