dotfiles

My personal shell configs and stuff
git clone git://git.alex.balgavy.eu/dotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

it2setkeylabel (3135B)


      1 #!/bin/bash
      2 
      3 # tmux requires unrecognized OSC sequences to be wrapped with DCS tmux;
      4 # <sequence> ST, and for all ESCs in <sequence> to be replaced with ESC ESC. It
      5 # only accepts ESC backslash for ST.
      6 function print_osc() {
      7     if [[ $TERM == screen* ]] ; then
      8         printf "\033Ptmux;\033\033]"
      9     else
     10         printf "\033]"
     11     fi
     12 }
     13 
     14 # More of the tmux workaround described above.
     15 function print_st() {
     16     if [[ $TERM == screen* ]] ; then
     17         printf "\a\033\\"
     18     else
     19         printf "\a"
     20     fi
     21 }
     22 
     23 function show_help() {
     24     echo "Usage:" 1>& 2
     25     echo "   $(basename $0) set Fn Label" 1>& 2
     26     echo "     Where n is a value from 1 to 20" 1>& 2
     27     echo "   $(basename $0) set status Label" 1>& 2
     28     echo "     Sets the touch bar status button's label" 1>& 2
     29     echo "   $(basename $0) push [name]" 1>& 2
     30     echo "     Saves the current labels with an optional name. Resets labels to their default value, unless name begins with a "." character." 1>& 2
     31     echo "   $(basename $0) pop [name]" 1>& 2
     32     echo "     If name is given, all key labels up to and including the one with the matching name are popped." 1>& 2
     33     echo "" 1>& 2
     34     echo "Example:" 1>& 2
     35     echo "#!/bin/bash" 1>& 2
     36     echo "# Wrapper script for mc that sets function key labels" 1>& 2
     37     echo "NAME=mc_\$RANDOM" 1>& 2
     38     echo "# Save existing labels" 1>& 2
     39     echo "$(basename $0) push \$NAME" 1>& 2
     40     echo "$(basename $0) set F1 Help" 1>& 2
     41     echo "$(basename $0) set F2 Menu" 1>& 2
     42     echo "$(basename $0) set F3 View" 1>& 2
     43     echo "$(basename $0) set F4 Edit" 1>& 2
     44     echo "$(basename $0) set F5 Copy" 1>& 2
     45     echo "$(basename $0) set F6 Move" 1>& 2
     46     echo "$(basename $0) set F7 Mkdir" 1>& 2
     47     echo "$(basename $0) set F8 Del" 1>& 2
     48     echo "$(basename $0) set F9 Menu" 1>& 2
     49     echo "$(basename $0) set F10 Quit" 1>& 2
     50     echo "$(basename $0) set F11 Menu" 1>& 2
     51     echo "$(basename $0) set F13 View" 1>& 2
     52     echo "$(basename $0) set F14 Edit" 1>& 2
     53     echo "$(basename $0) set F15 Copy" 1>& 2
     54     echo "$(basename $0) set F16 Move" 1>& 2
     55     echo "$(basename $0) set F17 Find" 1>& 2
     56     echo "mc" 1>& 2
     57     echo "# Restore labels to their previous state" 1>& 2
     58     echo "$(basename $0) pop \$NAME" 1>& 2
     59 }
     60 
     61 ## Main
     62 if [[ $# == 0 ]]
     63 then
     64   show_help
     65   exit 1
     66 fi
     67 
     68 if [[ $1 == set ]]
     69 then
     70   if [[ $# != 3 ]]
     71   then
     72     show_help
     73     exit 1
     74   fi
     75   print_osc
     76   printf "1337;SetKeyLabel=%s=%s" "$2" "$3"
     77   print_st
     78 elif [[ $1 == push ]]
     79 then
     80   if [[ $# == 1 ]]
     81   then
     82     print_osc
     83     printf "1337;PushKeyLabels"
     84     print_st
     85   elif [[ $# == 2 ]]
     86   then
     87     if [[ $2 == "" ]]
     88     then
     89       echo "Name must not be empty" 1>& 2
     90       exit 1
     91     fi
     92     print_osc
     93     printf "1337;PushKeyLabels=%s" "$2"
     94     print_st
     95   else
     96     show_help
     97     exit 1
     98   fi
     99 elif [[ $1 == pop ]]
    100 then
    101   if [[ $# == 1 ]]
    102   then
    103     print_osc
    104     printf "1337;PopKeyLabels"
    105     print_st
    106   elif [[ $# == 2 ]]
    107   then
    108     if [[ $2 == "" ]]
    109     then
    110       echo "Name must not be empty" 1>& 2
    111       exit 1
    112     fi
    113     print_osc
    114     printf "1337;PopKeyLabels=%s" "$2"
    115     print_st
    116   else
    117     show_help
    118     exit 1
    119   fi
    120 else
    121   show_help
    122   exit 1
    123 fi