dotfiles

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

it2universion (1856B)


      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 8" 1>& 2
     26   echo "  $(basename $0) set 9" 1>& 2
     27   echo "  $(basename $0) push [name]" 1>& 2
     28   echo "     Saves the current version with an optional name." 1>& 2
     29   echo "  $(basename $0) pop [name]" 1>& 2
     30   echo "     If name is given, all versions up to and including the one with the matching name are popped." 1>& 2
     31 }
     32 
     33 function set_version() {
     34   print_osc
     35   printf "1337;UnicodeVersion=$1"
     36   print_st
     37 }
     38 
     39 function push_version() {
     40   print_osc
     41   printf "1337;UnicodeVersion=push $1"
     42   print_st
     43 }
     44 
     45 function pop_version() {
     46   print_osc
     47   printf "1337;UnicodeVersion=pop $1"
     48   print_st
     49 }
     50 
     51 ## Main
     52 if [[ $# == 0 ]]
     53 then
     54   show_help
     55   exit 1
     56 fi
     57 
     58 if [[ $1 == set ]]
     59 then
     60   if [[ $# != 2 ]]
     61   then
     62     show_help
     63     exit 1
     64   fi
     65   set_version $2
     66 elif [[ $1 == push ]]
     67 then
     68   if [[ $# == 1 ]]
     69   then
     70     push_version ""
     71   elif [[ $# == 2 ]]
     72   then
     73     if [[ $2 == "" ]]
     74     then
     75       echo "Name must not be empty" 1>& 2
     76       exit 1
     77     fi
     78     push_version "$2"
     79   else
     80     show_help
     81     exit 1
     82   fi
     83 elif [[ $1 == pop ]]
     84 then
     85   if [[ $# == 1 ]]
     86   then
     87     pop_version ""
     88   elif [[ $# == 2 ]]
     89   then
     90     if [[ $2 == "" ]]
     91     then
     92       echo "Name must not be empty" 1>& 2
     93       exit 1
     94     fi
     95     pop_version "$2"
     96   else
     97     show_help
     98     exit 1
     99   fi
    100 else
    101   show_help
    102   exit 1
    103 fi
    104