You are not logged in.

#1 2021-03-27 07:32:48

seth
Member
Registered: 2012-09-03
Posts: 51,213

[RFC] [WIP] [Draft] J.A.R.V.I.S.

Just Another Runner and I'll come up w/ sth. for the rest… later.

Ever unhappy w/ most available runners, the idea is to have a convenient cross over between genericrunner™ and a (quake like) terminal window which always seems in the way.
So the idea i hacked up last night is single line shell in an (ideally override-redirect) window that allows me to run stuff but also dynamically expand for a growing set of functions (shadowing popular binaries because I'm not re-learning this…) so that I can use it to inspect file, check top, control mpd etcetc. in space and then auto-hides when losing focus.

This way I get a runner w/ the autocompletion comfort of zsh/bash/thereareactuallysomefishusersinthisforum and transient access to a terminal that will be neither to large nor no small nor on a different workspace nor stashed below a bunch of other windows nor obstructing them.

The code below is "runnable" but full of hardcoded local stuff (urxvt, fonts, background images, another script that allows me to align to daylight etc.)

=> What I want to know at this point is whether this is self-masturbative nonsense or there's enough interest in the principal idea to generalize it into a distributable program (modular function extension, configurable VTE, less hardcoded binaries, stuff).

jarvis

#!/bin/sh

. $HOME/bin/.funcs/daytime

REVERSE=""
BACKDROP="$HOME/wallpapers/urxvt/jarvis_cyan.png;style=centered"
if is_day; then
    REVERSE="-rv"
    BACKDROP="$HOME/wallpapers/urxvt/jarvis_black.png;style=centered"
fi

([ "`xdotool getwindowfocus`" = "`xdotool search --limit 1 --classname JARVIS`" ] && \
xdotool search --all --onlyvisible --classname JARVIS windowunmap >/dev/null 2>&1) || \
xdotool search --all --classname JARVIS windowmap windowfocus >/dev/null 2>&1 || \
env JARVIS=true urxvt $REVERSE -name JARVIS -fn "xft:SourceCodePro-9" -geometry 100x1+200+48 -pixmap "$BACKDROP" -override-redirect &
disown

# focus
sleep 0.5
xdotool search --onlyvisible --classname JARVIS windowfocus >/dev/null 2>&1

utils.sh, sourced by the shell rc depending on the JARVIS environment set above

# blinking beam cursor
printf '\x1b[\x35 q'

if [ -z "$JARVIS_AUTOHIDES" ]; then
    xdotool behave $WINDOWID blur exec zsh -c \
        '[ "$(xdotool getwindowfocus)" -eq "$WINDOWID" ] || \
         xdotool windowunmap "$WINDOWID" >/dev/null  2>&1' &
    disown
fi
JARVIS_AUTOHIDES=true

jarvis_resize() {
    printf "\x1B[8;${1:-1};${2:-100}t"
    clear
}

# wiki ========================================

jarvis_wiki() {
    WLC="$1"; shift
    jarvis_resize 48
    wikicurses -w $WLC "$*"
    jarvis_resize
}

explain() {
    jarvis_wiki en "$*"
}
erkläre() {
    jarvis_wiki de "$*"
}

help() {
    jarvis_wiki arch "$*"
}

# ============================================================================

give() {
    TOKEN="$*"
    DST=${TOKEN##* in }
    SRC=${TOKEN%% in *}
    printf "${SRC%% } are %s ${DST## }" $(units -t "$SRC" "$DST")
    sleep 5
    echo
}

alias jarvis_less=/usr/bin/less -J -N -w --mouse --rscroll …

less() {
    jarvis_resize 48
    sleep 0.1 # less'ing from stdin otherwise forks - there's probably a cleaner way for this
    jarvis_less -f -- "${1:-/dev/stdin}"
    jarvis_resize
}

edit() {
    jarvis_resize 48
    CANARY="$1"
    [ -e "$CANARY" ] || CANARY="$(dirname "$CANARY")"
    if [ -w "$CANARY" ]; then
        vim -p "$@"
    else
        sudoedit "$1"
    fi
    jarvis_resize
}

stat() {
    jarvis_resize 9
    /usr/bin/stat "$@" | jarvis_less
    jarvis_resize
}

dict() {
    jarvis_resize 16
    case "$1" in
        "en")
            shift
            /usr/bin/dict -d fd-deu-eng "${@}" 2>&1 | jarvis_less
        ;;
        "de")
            shift
            /usr/bin/dict -d fd-eng-deu "${@}" 2>&1 | jarvis_less
        ;;
        "fr")
            shift
            /usr/bin/dict -d fd-deu-fra "${@}" 2>&1 | jarvis_less
        ;;
        *)
            /usr/bin/dict "$@" 2>&1 | jarvis_less
        ;;
    esac
    jarvis_resize
}

man() {
    jarvis_resize 48
    /usr/bin/man $@
    jarvis_resize
}


ncmpcpp() {
    jarvis_resize 32
    /usr/bin/ncmpcpp
    jarvis_resize
}

top() {
    jarvis_resize 24
    /usr/bin/top
    jarvis_resize
}

alsamixer() {
    jarvis_resize 16 128
    /usr/bin/alsamixer
    jarvis_resize
}

mc() {
    jarvis_resize 32 128
    /usr/bin/mc
    jarvis_resize
}

systemctl() {
    case "$1" in
    "list"*|"status"|"show"|"cat"|*"help")
    jarvis_resize 24
    SYSTEMD_COLORS=true /usr/bin/systemctl --no-pager "$@" | jarvis_less -r
    jarvis_resize
    ;;
    "get"*|"is-"*)
    jarvis_resize 2
    SYSTEMD_COLORS=true /usr/bin/systemctl --no-pager "$@" | jarvis_less -r
    jarvis_resize
    ;;
    *)
    jarvis_resize 3
    sudo /usr/bin/systemctl "$@"
    jarvis_resize
    ;;
    esac
}

Offline

Board footer

Powered by FluxBB