#!/bin/bash APP_SVNID='$HeadURL$ $LastChangedRevision$' # Modules . $(ade-config ade_share_prefix)/include/ade.sh || { echo "${0##*/}: INTERNAL ERROR: failed to load ade.sh" >&2; exit 3; } # Errors LXADESH_DEFINED_ERRORS=( "KEY=LXADESH_ERR_MISC; FMT=\"%s\"" ) # Options # (no need to define here) # Other globals # The next line is extracted by 'adegmt -l'. After adegmt has been used to get this template the line can be removed. # ADEGMT-LIST-HINT: ADE-based bash script implementing lx(1) lxadesh() { local ERRSTACK_REF="$1"; shift local RC LABEL local -a NEW_DOLLAR_AT local ISRELABELABLE_FLAG # Defaults for options OPT_FORCE=false OPT_LABELWHAT=0 # Register errors, options and callbacks ade_register_error_types LXADESH_DEFINED_ERRORS ade_register_options "$ERRSTACK_REF" -o iwbF --longoptions=icon,window,both,force --callback-template="handle_option_%s" || return $? ade_set_callbacks "$ERRSTACK_REF" lxadesh_usage_help lxadesh_version lxadesh_paths || return $? # Process options ade_process_options "$ERRSTACK_REF" NEW_DOLLAR_AT "$@" || return $? set -- "${NEW_DOLLAR_AT[@]}" # Process arguments LABEL="${*:- }" # Sanity checks and derivations if { ! $OPT_FORCE; } && { is_relabelable_term "$ERRSTACK_REF" "$TERM" ISRELABELABLE_FLAG; ! $ISRELABELABLE_FLAG; }; then ade_error "$ERRSTACK_REF" LXADESH_ERR_MISC "the title of this sort of terminal cannot be changed by this program (is 'TERM' set correctly?)" return $ADE_FAIL fi # Guts echo -n "]$OPT_LABELWHAT;$LABEL" return $ADE_OK } # Option handlers handle_option_i() { local ERRSTACK_REF="$1"; shift OPT_LABELWHAT=1 return $ADE_OK } handle_option_icon() { handle_option_i "$@" } handle_option_w() { local ERRSTACK_REF="$1"; shift OPT_LABELWHAT=2 return $ADE_OK } handle_option_window() { handle_option_w "$@" } handle_option_b() { local ERRSTACK_REF="$1"; shift OPT_LABELWHAT=0 return $ADE_OK } handle_option_both() { handle_option_b "$@" } handle_option_F() { local ERRSTACK_REF="$1"; shift OPT_FORCE=true return $ADE_OK } handle_option_force() { handle_option_F "$@" } # Callbacks lxadesh_usage_help() { local ERRSTACK_REF="$1"; shift local USAGE_TEXT_SHORT_REF="$1"; shift local USAGE_TEXT_LONG_REF="$1"; shift eval "$USAGE_TEXT_SHORT_REF=\"\"" eval "$USAGE_TEXT_LONG_REF=\"\ -i | --icon label the icon only -w | --window label the window only -b | --both label both (default) -F | --force ignore 'TERM' and force labelling\"" return $ADE_OK } lxadesh_version() { local ERRSTACK_REF="$1"; shift local VERSION_REF=$1; shift ade_extract_version "$ERRSTACK_REF" "$APP_SVNID" "$VERSION_REF" return $ADE_OK } lxadesh_paths() { local ERRSTACK_REF="$1"; shift local PATHLIST_REF=$1; shift eval "$PATHLIST_REF=\"\"" return $ADE_OK } # Other functions is_relabelable_term() { local ERRSTACK_REF="$1"; shift local TERM=$1; shift local ISRELABELABLE_FLAG_REF=$1; shift local RC case "$TERM" in rxvt|xterm|xterm-debian|cygwin) eval "$ISRELABELABLE_FLAG_REF=true" ;; *xterm*) ade_warning "$ERRSTACK_REF" LXADESH_ERR_MISC "guessing this is some sort of xterm" eval "$ISRELABELABLE_FLAG_REF=true" ;; vt100) { expr "X$TERMCAP" : 'XSC|' > /dev/null && eval "$ISRELABELABLE_FLAG_REF=true"; } || eval "$ISRELABELABLE_FLAG_REF=false" ;; *) eval "$ISRELABELABLE_FLAG_REF=false" ;; esac return $ADE_OK } # Entry point ade_main lxadesh "$@"