shiftdot515

dot.mkshrc

Mar 29th, 2019 (edited)
589
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 36.57 KB | None | 0 0
  1. #!/var/bin/mksh
  2. #-*- Mode: Shell-script;-*-
  3. set -a # turn on autoexport
  4. PATH=/bin:/sbin:/usr/bin:/usr/sbin${DISPLAY:+:/usr/X11R6/bin}
  5. PATH=~/bin:/var/bin:~/l/bin:$PATH:/a/a/sbin:/a/a/bin
  6. #MANPATH=/usr/X11R6/man:/usr/local/man:/Users/daniel/bsd
  7. MANPATH=~/l/man:/a/a/man:
  8. #DYLD_LIBRARY_PATH=/a/a/lib
  9. DYLD_FALLBACK_LIBRARY_PATH=/a/a/lib
  10. #DYLD_FALLBACK_LIBRARY_PATH=${HOME}/lib:${HOME}/l/lib:/usr/local/lib:/lib:/usr/lib:/a/a/lib
  11. #see ~/.MacOSX/environment.plist
  12. PAGER=most  #that's the*lostsouls*version early linux user mod.
  13. # I really need to get away  from this habbit  
  14. EDITOR=ed
  15. VISUAL=nvi
  16. #BLOCKSIZE=1k
  17. umask 022
  18.  
  19. HOST="$(hostname)"
  20. HOSTNAME=${HOST}
  21. HOSTNAME=gorf
  22. set +a # turn off autoexport
  23.  
  24. HISTFILE=${HOME}/.mksh_history
  25. HISTSIZE=200
  26. #PS1="%"
  27.  
  28. ##unset ENV # breaks man if set
  29. unset ENV
  30. #set -o noclobber
  31. #ulimit -c 0
  32. #ulimit -n 1024
  33. ulimit -c unlimited
  34. ##### aliases ###############
  35. #alias prepwd='PATH=$PWD:$PATH'
  36. #alias oldpwd="PATH=$PATH"
  37. #alias postpwd='PATH=$PATH:$PWD'
  38. #alias dropcd='read&&cd $(dirname "$REPLY")'
  39. #path+ path-
  40. #saved store PWD into array
  41. #restored restore from array
  42.  
  43. alias doy="date '+%j'"
  44. alias ydoy="date '+%j%y'"
  45. alias yydoy="date '+%j%Y'"
  46. alias vdt="date '+%v'"
  47. alias dt="date '+%D %r'"
  48. alias dt0="date '+%D'"
  49. alias dt1="date '+%r'"
  50. alias isodate="date '+%G-%m-%d'"
  51. alias isodt="date '+%G-%m-%d %H:%M'"
  52. alias isodts="date '+%G-%m-%d %H:%M:%S'"
  53. alias extcd='drutil -drive external'
  54. #alias enter="eject -l"
  55. alias ethers="arp -a | sed -n '{
  56. s/on .*$//
  57. s/ (.*) at//
  58. p
  59. }'"
  60. alias a='ls -a'
  61. alias c='ls -CF'
  62. alias d0="ls -1p | grep '/$'"
  63. alias d="ls -1p | sed -n '/\/$/s/^/    /p;'"
  64. alias dl="ls -lhp | grep '^d'"
  65. alias DL="ls -lTthp | grep '^d'"
  66. alias gq='grep -q -- '
  67. alias g1='grep -m 1 -- '
  68. alias gg='grep -H -- '
  69. alias gn='grep -n -- '
  70. alias ggg='grep -nH -- '
  71. alias go='grep -Ho -- '
  72. alias h='grep -h -- '
  73. alias g=grep
  74. alias i='grep -iI --mmap -- '
  75. # above fails when with find . -type d | i patch  # seems to be the h?
  76. alias io='grep -iIo --mmap -- '
  77. alias ii='grep -iHI --mmap -- '
  78. alias ir='grep -iHIr --mmap -- '
  79. alias v='grep -v -- '
  80. alias f="ls -1p | sed -n '/[^\/]$/s/^/    /p;'"
  81. alias 0='ls -1fp'
  82. alias 1=0
  83. alias t='ls -1ptr'
  84. alias tt='ls -LTlhrt'
  85. alias lt='ls -Lgnht'
  86. alias x='ls -xF'
  87. alias r='ls -1RF'  
  88. alias r='ls -1RF'  
  89. alias rr='ls -lRF'  
  90. alias R='BLOCKSIZE=1m ls -s1R'
  91. alias l='ls -lp'
  92. alias ll='ls -lh'
  93. alias lll='ls -Llh'
  94. alias lc='l | sort -n +4'
  95. alias lm='BLOCKSIZE=1m ls -sF'
  96. alias lmm='BLOCKSIZE=1m ls -1sSF'
  97. alias dm='BLOCKSIZE=1m du -c'
  98. alias bytes="stat -f '%z' "
  99. alias bytesL="stat -f '%Lz' "
  100. alias dirs="ls -1Ap | grep '/$' | column"
  101. alias files="ls -1AF | sed  '/[@/]$/d;s/\*$//' |column"
  102. alias files1="ls -1AF | sed  '/[@/]$/d;s/\*$//'"
  103. alias files2="ls -1F | sed  '/[@/]$/d;s/\*$//'"
  104. alias syms="ls -1AF | grep '@$'"
  105. alias tree="tree -Ad"
  106. alias aux='ps aux'
  107. alias vax='ps vax'
  108. alias jax='ps jax'
  109. alias lax='ps lax'
  110. alias axl='ps axl'
  111. alias ax='ps ax'
  112. alias cax='ps cax'
  113. alias caxl='ps caxl'
  114. alias pcpu='ps rcxo pcpu,pid,uid,command'
  115. alias hpcpu='ps rcxo pcpu,pid,uid,command|head'
  116. alias pmem='ps mxco pmem,pid,uid,command'
  117. alias ptop='ps mcxo pcpu,pmem,pid,uid,command | head -n $(( LINES - 3 ))'
  118. alias mem='ps mxco rss,pid,uid,command'
  119. alias netcat=/usr/bin/nc
  120. alias 1ping='command ping -qc 1 -t 2'
  121. alias 0ping='command ping'
  122. alias vi=nvi
  123. alias ex=nex
  124. alias virc='vi ~/.mkshrc'
  125. alias viewrc='view ~/.mkshrc'
  126. alias mvi='mv -iv'
  127. alias hog='BLOCKSIZE=1m du -s *| sort -n'
  128. alias big='R | grep -v ':$' | sort -n | tail -20'
  129. alias cpin='cpio -ivmud'
  130. alias cpout='cpio -ov -H ustar'
  131. alias cpoutposix='cpio -ovud -H odc'
  132. alias cplist='cpio -itv'
  133. alias cpthru='cpio -pvmaud'  
  134. alias cpupdate='cpio -pvmad' ## ???
  135. alias paxthru0='pax -r -w -0dv -pp --force-local'
  136. alias usbls='system_profiler SPUSBDataType'
  137. alias firewirels='system_profiler -detailLevel full SPFireWireDataType'
  138. alias displayinfo='system_profiler SPDisplaysDataType'
  139. alias resolution="displayinfo | sed -n '/Resolution:/s/Resolution://p'"
  140. alias dishz="resolution | sed -n '1s/.* @ //p'"  
  141. alias dismode="displayinfo | sed -n '/Resolution:/{N;s/^ *Resolution://;s/\n *Depth://;y/-@\nC/   c/;p;}'"
  142. alias dos2unix='tr -d "\015"'
  143. alias mac2unix='tr "\015" "\012"'
  144. alias unix2mac='tr "\012" "\015"'
  145. alias sansnewline='tr -d "\012"'  
  146. ## example ## sed -f iTunesEq.sed < feedin | tr -d "\012" > /tmp/thisfile    
  147. alias shredit='shred -zuvn3'
  148. alias shred0='shred -zuvn0'
  149. alias screencap='sleep ${DELAY:-4}; beep 1;screencapture -m /tmp/screencap$(doy).png'
  150. alias screencapselect='screencapture -iWc'
  151. alias winsplit='SHELL=/var/bin/mksh window -d -e ^^'
  152. alias susu='su wheel -c su - -'
  153. alias typescript='script /tmp/typescript.$$.$(doy)'
  154. alias typescripta='script -a /tmp/typescript.$(doy)'
  155. #alias typescriptv='script -a ~vt/typescript.$(doy)'
  156. alias {}='cat - > /dev/null'
  157. alias elf='cat - >> elf'
  158. alias showelf='cat elf'
  159. alias dwarf='showelf;elf'
  160. alias dog='{}'
  161. alias zz='alias -dp;'          # directory aliases
  162. #alias zzz='alias -d ~=$PWD' # alias ~~      
  163. alias zzz='alias -d ~=$OLDPWD' # alias ~~      
  164. alias P='alias -d P=$PWD'
  165. alias Q='alias -d Q=$PWD'
  166. alias A='alias -d A=$PWD'
  167. alias B='alias -d B=$PWD'
  168. alias C='~/bin/awk/Celsius <<< '  # still need to start line with C or F
  169. alias ldd='otool -L '
  170. alias sq3='sqlite3'
  171. alias patch='patch -b --verbose'
  172. alias rows="stty -a | sed -n '1{s/^.* baud; //;s/ rows.*columns;$//;p;}'"
  173. alias stars="tr '\000' '*'< /dev/zero"
  174. alias stars1="jot -n -b '*' -s '' 0"
  175. alias stars2="tr -u '\000' '*'< /dev/zero"
  176. alias agethisyear='echo "You are $(( $(date +\%Y) - ${BIRTHYEAR:-1972 })) this year."'
  177. alias agedaddied='echo 42. Dad died Nov. 21st 2014'
  178. alias wireless='LF;CR;tr -dc "[A-Za-z0-9]" < /dev/random | gdd bs=1 count=63 delay=50 2> /dev/null;LF;LF'
  179. alias fold71='fold -s -w71'
  180. alias fn='echo $(( $(date +%W) / 2 ))'
  181. #alias systemlog='syslog -F bsd -l 7,6,5,4,3,2,1 ; syslog -w -F bsd -l 7,6,5,4,3,2,1'
  182. alias systemlog='(syslog -F bsd ; syslog -w -F bsd)'
  183. alias word='ispell -S <<<'
  184. alias starcraft='open -a /Users/daniel/games/Start\ Starcraft.app'
  185. #
  186. # decoder ring encryption
  187. alias hal0="tr '0-45-9AB-Zxyza-w_ ' '5-90-4ZA-Yabcd-z _'"
  188. alias ibm0="tr '5-90-4ZA-Yabcd-z _' '0-45-9AB-Zxyza-w_ '"
  189. alias hal="tr '0-45-9AB-Zxyza-w_ \013\213' '5-90-4ZA-Yabcd-z _\213\013'"
  190. alias ibm="tr '5-90-4ZA-Yabcd-z _\213\013' '0-45-9AB-Zxyza-w_ \013\213'"
  191.  
  192.  
  193. addto(){
  194. local file="${1}"
  195. shift || return
  196. cat - >> "${file}" <<< "$@"
  197. sofile="${file}"
  198. }
  199. alias so='addto ${sofile} $@'
  200. alias sowhat='print ${sofile-so};cat ${sofile-so};print ${sofile-so};'
  201. ping(){
  202. global pingwhat="${1:-$pingwhat}"
  203. 1ping ${pingwhat:-www.google.com} | sed '2,3{d;};${s/^round-.*=//;y/\// /;}'  
  204. ## can I get out, on the information superhighway?
  205. ## well, that was a bit of fun, with sed.
  206. }
  207.  
  208. #########functions#############################
  209. line(){ sed -n ${1:-\$}'{p;q;}' ${2} ;}
  210. line0(){ sed -n ${1}p ${2} ;}
  211. lines(){ sed -n ${1},${2}'{p;}' ${3} ;}
  212. ##a delete alias for things like ping| sed '2,3{d;}' ?
  213.  
  214. #peek(){ ls -lh $1 ;head $1 ; cksum $1 ;tail $1 ; }
  215. peek(){ cksum $1; head $1 ; ls -lh $1 ;tail $1 ; }
  216. peek2()
  217. {
  218.     echo -n '### chksum ###' ;cksum $1;
  219.     head $1;
  220.     echo -n '###### '; ls -lh $1;
  221.     tail $1
  222. }
  223. altls(){  # alternate between various ls #maybe cls if too down
  224. local ls="lacltsx"  # one of the single letter ls aliases
  225. integer i="$(( $SECONDS % ${#ls} ))" # no + 1 bc ${var:pos:len} is zero based
  226. local a
  227.  if (( ${#1} > 0 )) then
  228.    sleep 1.1       # really, we shouldn't hit this branch, but like to know
  229.    command ls "$@"
  230.  elif [[ s = ${ls:$i:1} ]] then
  231.     ls -l | sort -n +4
  232.  else
  233.   #removeremarklater
  234.    a=$(alias "${ls:$i:1}") # grab the alias definition
  235.    a=${a%\'}  # remove single ' at end
  236.    a=${a#?\=\'}    # remove first char (anychar) = then '
  237.    echo -e "\015\e[A\e[0K${PS4}${a}";$a  
  238.  fi
  239. }  # this is breaking and I don't care
  240.  
  241. copy(){
  242. if [[ $# == 0 ]]
  243. then
  244.   print "Copy what?"
  245.   print "    $copy_what"
  246. fi
  247. if [[ $# != 1 ]]
  248. then
  249.     print copy
  250.     print " usage:"
  251.     print "      copy filename"
  252.     print "      copy /something/filepath/filename"
  253.     print "  saves that filename, to copy it later"
  254.     print "      copy ."
  255.     print "  copies previously select file to where you, presently, are."
  256. fi
  257. if [[ '.' == "$1" ]]
  258. then
  259.     cp -iv "$copy_what" .
  260. else
  261.      copy_what="$1"
  262.      # not quite done, need to check to see if contains /
  263.      # then add $PWD if not
  264.      # then sanity check by either -f or -r
  265.      # on copy_what
  266.      # if fails then remark and clear it    
  267. fi
  268. }
  269.  
  270.  
  271.  
  272.  
  273.  
  274. getkey(){ #read a singlekey from the keyboard, put it in $gotkey
  275. local save
  276. save=`stty -g`              # save tty state
  277. stty -echo -icanon -isig eof ''      # set raw mode
  278. gotkey=`dd count=1 bs=1 2>/dev/null`   # read a single char
  279. stty $save
  280. }  # originally from my bash2.xx .bashrc, hardly use it these days,
  281.  
  282.  
  283. pressakey(){  # why use the above, when mksh has more features, than original Bourne shell, etc?
  284.   print "Press a key."
  285.   INVISIBLE
  286.   read -rN 1
  287.   INVISIBLENOT
  288.   CR  # cosmetic fixup, bc will prompt begins, 1 character out of place, w/o.
  289. }
  290.  
  291. #####
  292. beep() {
  293.         typeset -i i=${1:-1}
  294.         while (( i > 0 ))
  295.         do
  296.                 echo "\a\c"
  297.                 (( i = i - 1 ))
  298.                 sleep ${beepdelay:-0.6}
  299.         done
  300. }
  301. emacsr(){  # resume emacs, passing new args, needs 'resume
  302.  echo "$PWD" "$@" >| ~/.emacs.d/.emacs_args && fg %?emacs
  303. }
  304. M(){   #on any BSD you should man ./man.1 etc
  305. # then Sun went to Solaris --- I should prune this.. should use $@ meh
  306. for M in $* ;
  307. do
  308.   nroff -man $M | $PAGER
  309. done
  310. }
  311. ###################
  312. showchanges(){
  313. if [ -z $1 ];
  314. then
  315.     for R in *.~1~ ;
  316.     do
  317.        latest=$(basename $R .~1~ )
  318.        if [ -w $latest ];
  319.        then
  320.           echo "$latest"
  321.        else
  322.           echo -e "$latest \t(!locked)"
  323.        fi
  324.     done
  325. else
  326.     orig="${1}.~1~";
  327.     if [ ! -f $orig ]; then
  328.         echo $1 has not changed.;
  329.         return 1;
  330.     fi;
  331.     ( echo "$1        (original vs current)" ;
  332.     diff $orig $1 ;
  333.     echo "---- $1 --- " ) | most
  334. fi
  335. }
  336.  
  337. mkedscript()
  338. {
  339. for R in *.~1~;
  340. do
  341.    latest=$( basename $R .~1~ )
  342.    echo "e $latest"
  343.    diff -e $R $latest
  344.    echo "w"
  345. done
  346. echo "q"
  347. }
  348.  
  349. compare2files()
  350. {
  351.     if [ ! -r "$2" ]; then
  352.         echo NO $2;
  353.         return 2;
  354.     fi;
  355.     if cmp -s $1 $2; then
  356.         echo $1 SAME $2;
  357.         return 0;
  358.     else
  359.         echo "$1 DIFF $2";
  360.         return 1;
  361.     fi
  362. }
  363.  
  364.  
  365. findexecs(){
  366. local dir=${1:-.}
  367. shift
  368. find $dir -type f -perm -+x "$@"
  369. }
  370. # see jot
  371. yes-n(){   #yes but with echo -n, but strips newline.
  372. yes $@ | tr -ud '\n'  
  373. }
  374.  
  375. mbfree(){
  376. echo " $(( $(vm_stat | sed -n '2{
  377. s/^Pages free:[     ]//
  378. s/.$//
  379. p
  380. q
  381. }') / 256  ))"    
  382. # divide by 256 instead of * 4096 / 1024 / 1024  
  383. }
  384. commands(){
  385. local ps_out=$(ps cxo command,pid,start)
  386. sed 1d <<<${ps_out}| sort -k 1,1
  387. }
  388. commandsa(){
  389. local ps_out=$(ps cAo command,pid)
  390. sed 1d <<<${ps_out}| sort -k 1,1
  391. }
  392.  
  393. div(){  
  394. echo "$1  div 8 = $(( $1 / 8 )) remainder $(( $1 % 8 )) "
  395. echo "$2  div 8 = $(( $2 / 8 )) remainder $(( $2 % 8 )) "
  396. echo ""
  397. echo "$1 div 16 = $(( $1 / 16 )) remainder $(( $1 % 16 )) "
  398. echo "$2 div 16 = $(( $2 / 16 )) remainder $(( $2 % 16 )) "
  399. }  #mpeg4 useful
  400.  
  401. new(){
  402.  local script=""
  403.  if [[ "finder" == "$1" ]]  # make a new terminal window for each finder window
  404.  then
  405.  osascript <<'EOF'
  406. tell application "Finder"
  407.     get Finder windows
  408.     copy result to Winlist
  409.     repeat with R in Winlist
  410.         get target of R
  411.         get result as string
  412.         get POSIX path of result
  413.         set S to "cd " & result
  414.         tell application "Terminal" to do script S
  415.      end repeat
  416. end tell
  417. EOF
  418.  return
  419.  elif [[ -d "$1" ]]
  420.  then
  421.     script="cd ${1}"
  422.  elif [[ -n "$1" ]]
  423.  then
  424.     script="$@"  
  425.  elif [[ "${PWD}" != "${HOME}" ]]
  426.  then
  427.     script="cd ${PWD}"
  428.  fi
  429.  osascript -e $'tell app "Terminal" to do script"' -e "$script" -e $'"'
  430. }
  431.  
  432.  
  433.  
  434.  
  435. prompt(){
  436.  
  437. case $1 in
  438.  '?'|what)
  439.   print "PS1=$PS1"
  440.   print "PS2=$PS2"
  441.   print "PS3=$PS3"
  442.   print "PS3=$PS4"
  443.   ;;
  444.   ?)   # any single character
  445. PS1="${1} " ;;
  446.  
  447.   title1|xterm*)
  448. PS1=']2;${USER}@${HOSTNAME}:${PWD}[${USER}@${HOSTNAME}:${PWD}]
  449. ]1;${PWD##/*/}%'
  450.   ;;
  451.   title2|rxvt)
  452. PS1=']2;${USER}@${HOSTNAME}:${PWD}[${USER}@${HOSTNAME}:${PWD}]
  453. ]1;${HOSTNAME}:${PWD##/*/}%'
  454.   ;;
  455.   min)
  456. PS1='${PWD##/*/})'
  457.   ;;
  458.   vi)
  459. PS1='[$?]';;
  460.   root) #datetime#shortdir#
  461. #PS1=" \$(isodts)#{PWD##/*/}#"
  462. #PS1="#\$(isodts)#"
  463. PS1="\$(date '+%T')%"
  464.   ;;
  465.   lost|vt100)
  466. PS1='>:'   ;;
  467.   lost+|dtterm)
  468. PS1='$?:${PWD##/*/}>:'
  469.  ;;
  470.  lost/)
  471. PS1='<${PWD##/*/}>:'
  472.  ;;
  473.   lost-|vt102)
  474. PS1="$?>:"
  475. ;;
  476.  n*|normal|std)
  477. PS1='[${USER}@${HOSTNAME}:${PWD}]
  478. %'
  479.  ;;
  480.  *)
  481.  PS1='%'
  482.   ;;
  483. esac
  484. }
  485. test -x ~/bin/browse.mksh && . ~/bin/browse.mksh
  486.  
  487. ## dashboard ####
  488. alias dashoff='defaults write com.apple.dashboard mcx-disabled -boolean YES ;
  489. sleep 2 ; killall Dock ; echo Dashboard disabled.'
  490. alias dashon='defaults write com.apple.dashboard mcx-disabled -boolean NO ;
  491. sleep 2 ; killall Dock ; echo Dashboard enabled.'
  492. alias dashp='defaults read com.apple.dashboard mcx-disabled | grep -q 1 &&
  493. echo Dashboard is disabled. || echo Dashboard is enabled.'
  494. alias HideDesktop='defaults write com.apple.finder CreateDesktop FALSE ; killall Finder'
  495. alias ShowDesktop='defaults write com.apple.finder CreateDesktop TRUE ; killall Finder'
  496. alias dash="osascript - 2>/dev/null<<< 'tell app \"Dashboard\" to activate'"  
  497. ### terminal features #####################
  498. alias alert='beep 2;dock;beep 1;sleep 1.5;undock;beep 1'
  499. alias reset="$(whence stty) $(stty -g)||$(whence reset);echo -en '\e<\ec'"
  500. alias cls="echo -n $(tput clear| vis -o|sed 's/\\/\\\\/g')"
  501. alias echovtbox="print  '\0377'"
  502. alias echopcbox='echo -e "\0244\c"'
  503.  
  504. # cd to Finder , insertion location is where New Folder would happen
  505. # typically same a target of window 1, works if window 1 is textclipping
  506. ##alias cdfinder="cd $(osascript -ss -e $'tell app "Finder"\r get insertion location as string\r get POSIX path of result\r end tell' ) "
  507. ##alias cdil="echo $(osascript -ss -e $'tell app "Finder"\r get insertion location as string\r get POSIX path of result\r end tell' ) "
  508. mute(){ osascript <<< \
  509. "set volume output muted (not (get output muted of (get volume settings)))" ; }
  510. volume(){  # 0 to 100
  511. local volume
  512. volume=$(osascript -ss -e $'output volume of (get volume settings)')
  513. osascript -e "set volume output volume ${1:-$volume}"
  514. print "volume was $volume" ; }
  515. pause(){
  516. osascript <<< 'tell application "iTunes" to if player position is not missing value then playpause'
  517. }
  518. skip(){ osascript <<< 'tell application "iTunes" to next track' ; }
  519. repeat(){  # yeah, I did start merely imitating the existing feature
  520. case "$1" in
  521.   one|'')
  522.   osascript <<< 'tell application "iTunes" to set song repeat of current playlist to one' ;;
  523.   all)
  524.   osascript <<< 'tell application "iTunes" to set song repeat of current playlist to all' ;;
  525.   off)
  526.   osascript <<< 'tell application "iTunes" to set song repeat of current playlist to off' ;;
  527.  *) print "usage: [one|all|off] " ;;
  528. esac
  529. echo -n "Current is playlist is "
  530. osascript <<< 'tell app "iTunes" to get name of current playlist'
  531. echo -n "song repeat is "
  532. osascript <<< 'tell app "iTunes" to get song repeat of current playlist'
  533.  
  534. } # use AWK next
  535.  
  536.  
  537.  
  538. edfile(){ # no, explaination should be necessary, necessarily.
  539.  
  540. ed -p '%'"$1"'% ' $1
  541. }
  542.  
  543. ### terminal.app cde term xterm
  544. undock(){ echo -e "\e[1t\c" ; }    # de-iconify
  545. dock(){   echo -e "\e[2t\c" ; }    # iconify
  546. raise(){  echo -e "\e[5t\c" ; }     # also undocks
  547. lower(){  echo -e "\e[6t\c" ; }     # also undocks
  548. title(){  echo -e "\e]0;$@\a\c" ; }
  549. bell(){   echo -e "\a\c" ; }
  550. vtcls(){ echo -e "\e[H\e[J\c" ; } #
  551. vtsoft(){  echo -e '\e[!p\c' ; }  # soft reset
  552. vtnormal(){ echo -e '\e[0m\c' ; }
  553. alias n=vtnormal;   ## useful if the issue is infact invisible
  554. #emit(){   echo -en "$@ " ;  }  # space!  meh
  555. emit(){  echo -e "${1}\c" ; sleep ${2:-0} ; }
  556. statline(){ # create a???? pragma for purposeful interactive programming
  557. # yeah, that sounds so stupid, but a year later it still works,
  558. # it's just I can't improve upon it,----
  559. # they keyboard that's all.  
  560. # usecase:
  561. # 0:/tmp>:statline CURSOR 10 Paint
  562. # will do what
  563. # 0>/tmp>:cls; CURSOR 10 10; Paint; CURSOR  
  564. # will do, at the commandline prompt
  565. # Ive been here before
  566. vtcls
  567. eval $@
  568. CURSOR
  569. }
  570. vttoggle(){  # possibly a lot of things.. but right now just rev REVVIDEO
  571.   #meh getting bored just set up the switch
  572.    if [[ -z "${vttoggle}" ]]; then
  573.         vttoggle='r'
  574.    fi
  575.    #echo ${vttoggle:0:1}
  576.    if [[ ${vttoggle:0:1} == 'r' ]]  then
  577.        echo -e '\e[?5h\c' ;
  578.        vttoggle='R'
  579.    else
  580.        vttoggle='r'
  581.        echo -e '\e[?5l\c' ;
  582.    fi
  583. set +x  
  584. }
  585. #alias rm=dd
  586. ########### pbpaste related
  587. tweetline(){ pbcopy <<< "$@" ;}  #
  588. alias tweet='cat -uv|pbcopy'
  589. alias tweetcheck='pbpaste |cat -v;pbpaste | wc; pbpaste| ispell'
  590. alias comand=command
  591. alias lastlog='more /var/log/lastlog.log'
  592. ##alias @cd='cd $(pbpaste <<< "$PWD" )'
  593. alias emolument='pbcopy <<< emoluments'
  594.  
  595. #### XTERM related ########
  596. icontitile(){  echo -e "\e]1;$*\a\c" ; }   # change icon name
  597. windowtitle(){ echo -e "\e]2;$*\a\c" ; }   # change window title
  598.  
  599. xproperty(){   echo -e "\e]3;$*\a\c" ; } # set X prop=value #prop to delete
  600. xcolor(){      echo -e "\e]4;$1;$2\a\c" ; }  
  601. xxcolor(){     echo -e "\e]5;$1;$2\a\c" ; }
  602.  
  603.  
  604. G0(){ echo -e "\017\c" ; }  # SI CTRL-O switch to standard character set
  605. G1(){ echo -e "\016\c" ; }  # SO CTRL-N switch to alternate character set
  606. G2SS(){ echo -e "\eN\c" ; } # SS2 Single Shift Select of G2 character set
  607. G3SS(){ echo -e "\eO\c" ; } # SS3 Single Shift Select of G3 character set
  608. CHARSET(){
  609. case "${1:-default}${2}" in
  610. default) echo -e '\e%@\c' ;; # Select default character set  ISO 8859-1
  611. utf8)    echo -e '\e%G\c' ;; # Select UTF-8 character set (ISO 2022)
  612. G0|G0ascii)  echo -e '\e(B\c' ;; # USASCII
  613. G0line)      echo -e '\e(0\c' ;; # DEC Special Character and Line Drawing Set
  614. G0soft)      echo -e '\e( @\c' ;; # use soft set
  615. G0?)         echo -e "\e(${2}\c"  ;; # Designate G0 Character Set
  616. G1|G1ascii)  echo -e '\e)B\c' ;; # USASCII
  617. G1line)      echo -e '\e)0\c' ;; # line drawing
  618. G1soft)      echo -e '\e) @\c' ;; # use soft set
  619. G1?)         echo -e "\e)${2}\c"  ;; # Designate G1 Character Set
  620. G2|G2ascii)  echo -e '\e\*B\c' ;;
  621. G2line)      echo -e '\e*0\c' ;;
  622. G2soft)      echo -e '\e* @\c' ;; # use soft set
  623. G2?)         echo -e "\e*${2}\c"  ;; # Designate G2 Character Set
  624. G3|G3ascii)  echo -e '\e+B\c' ;;
  625. G3line)      echo -e '\e+0\c' ;;
  626. G3soft)      echo -e '\e+ @\c' ;; # use soft set
  627. G3?)         echo -e "\e\+${2}\c"  ;; # Designate G3 Character Set
  628. vt100)       echo -e '\e[?2h\c' ;; # set USASCII for G0-G3 and vt100 mode ???
  629. esac
  630. }
  631. #echo 531
  632. CR(){ echo -e "\015\c" ; }   # carriage return
  633. LF(){ echo -e "\012\c" ; }   # line need or new line
  634. TABSET(){
  635. #TABSET col 10 20 30 ...
  636. #TABSET clear_all
  637. #TABSET cleartab 20 25 30 ...
  638. case "${1}" in
  639.   col)
  640.       shift
  641.       for COL in $@
  642.       do
  643.         CURSOR column $COL
  644.         echo -e '\eH\c' # Horizontal Tab Set ## HTS
  645.       done;;
  646.   clear_all)
  647.      echo -e '\e[3g\c' ;;  # TBC clear all tabs (works)
  648.   clear_tab)
  649.       shift
  650.       for COL in $@
  651.       do
  652.         CURSOR column $COL
  653.         echo -e '\e[0g\c'  # TBC clear tab at current column
  654.       done ;;
  655.   *)      echo -e '\eH\c' ;; # Horizontal Tab Set ## HTS
  656. esac
  657. }
  658. SS2(){ echo -e '\eN\c' ; }   # Single Shift for one G2 character
  659. SS3(){ echo -e '\eO\c' ; }   # Single Shift for one G3 character
  660. DOUBLEHEIGHTLINETOP(){ echo -e "\e#3\c" ; }  #DECDHL  top half
  661. DOUBLEHEIGHTLINEBOT(){ echo -e "\e#4\c" ; }  #DECDHL  bottom half
  662. PRINTDOUBLEHEIGHT(){
  663. echo -n "$1"
  664. echo -e "\e#3"
  665. echo -n "${2:-$1}"   # bottom, default 2same, but allow experimentation
  666. echo -e "\e#4"
  667. SINGLEWIDTHLINE; # cleanup
  668. }
  669. SINGLEWIDTHLINE(){ echo -en "\e#5" ; }      #DECSWL
  670. DOUBLEWIDTHLINE(){ echo -en "\e#6" ; }      #DECDWL
  671. SCREENTEST(){      echo -en "\e#8" ; }  #DECALN screen alignmnet test
  672. NORMAL(){ echo -e '\e[0m\c' ; }   # character attributes
  673. BOLD(){ echo -e '\e[1m\c' ; }  
  674. UNDERLINE(){ echo -e '\e[4m\c' ; }
  675. BLINK(){ echo -e '\e[5m\c' ; }
  676. INVERSE(){ echo -e '\e[7m\c' ; }
  677. INVISIBLE(){ echo -e '\e[8m\c' ; }
  678. UNDERLINENOT(){ echo -e '\e[24m\c' ; }
  679. BLINKNOT(){ echo -e '\e[25m\c' ; }
  680. INVERSENOT(){ echo -e '\e[27m\c' ; }
  681. INVISIBLENOT(){ echo -e '\e[28m\c' ; }
  682. BLACK(){   echo -e '\e[30m\c' ; }
  683. RED(){     echo -e '\e[31m\c' ; }
  684. GREEN(){   echo -e '\e[32m\c' ; }
  685. YELLOW(){  echo -e '\e[33m\c' ; }
  686. BLUE(){    echo -e '\e[34m\c' ; }
  687. MAGENTA(){ echo -e '\e[35m\c' ; }
  688. CYAN(){    echo -e '\e[36m\c' ; }
  689. WHITE(){   echo -e '\e[37m\c' ; }
  690. COLORFG(){   echo -e "\e[38;5;${1:-0}m\c" ; } # 88/256 color support
  691. COLORBG(){   echo -e "\e[48;5;${1:-0}m\c" ; } # 88/256 color support
  692. ORIGINAL(){ echo -e '\e[39m\c' ; }
  693. BGBLACK(){  echo -e '\e[40m\c' ; }
  694. BGRED(){    echo -e '\e[41m\c' ; }
  695. BGGREEN(){  echo -e '\e[42m\c' ; }
  696. BGYELLOW(){ echo -e '\e[43m\c' ; }
  697. BGBLUE(){   echo -e '\e[44m\c' ; }
  698. BGMAGENTA(){ echo -e '\e[45m\c' ; }
  699. BGCYAN(){   echo -e '\e[46m\c' ; }
  700. BGWHITE(){  echo -e '\e[47m\c' ; }
  701. BGORIGINAL(){ echo -e '\e[49m\c' ; }
  702. HIBLACK(){   echo -e '\e[90m\c' ; }
  703. HIRED(){     echo -e '\e[91m\c' ; }
  704. HIGREEN(){   echo -e '\e[92m\c' ; }
  705. HIYELLOW(){  echo -e '\e[93m\c' ; }
  706. HIBLUE(){    echo -e '\e[94m\c' ; }
  707. HIMAGENTA(){ echo -e '\e[95m\c' ; }
  708. HICYAN(){    echo -e '\e[96m\c' ; }
  709. HIWHITE(){   echo -e '\e[97m\c' ; }
  710. BGHIBLACK(){  echo -e '\e[100m\c' ; }
  711. BGHIRED(){    echo -e '\e[101m\c' ; }
  712. BGHIGREEN(){  echo -e '\e[102m\c' ; }
  713. BGHIYELLOW(){ echo -e '\e[103m\c' ; }
  714. BGHIBLUE(){   echo -e '\e[104m\c' ; }
  715. BGHIMAGENTA(){ echo -e '\e[105m\c' ; }
  716. BGHICYAN(){   echo -e '\e[106m\c' ; }
  717. BGHIWHITE(){  echo -e '\e[107m\c' ; }
  718.  
  719. REVVID(){ echo -e '\e[?5h\c' ; } # reverse video (set private mode)
  720. NORMVID(){ echo -e '\e[?5l\c' ; }  # normal video (reset private mode)
  721. ALTSCREEN(){ echo -e '\e[?47h\c' ; }    # alternate screen buffer
  722. NORMSCREEN(){ echo -e '\e[?47l\c' ; } # use normal screen buffer
  723. ALTSCREENSC(){ echo -e '\e[?1049h\c' ; } # save cursor+alternate screen buffer
  724.  
  725. KEYPADAPP(){       echo -e '\e=\c' ; }    #Are these usable?
  726. KEYPADNORMAL(){    echo -e '\e>\c' ; }    #don't seem so # maybe I needed strict-vt set
  727.  
  728. SCREENMEMLOCK(){   echo -e '\el\c' ; } #characters above cursor are locked in
  729. SCREENMEMUNLOCK(){ echo -e '\em\c' ; } ##in place, clear screen undoes also.
  730. FULLRESET(){ echo -e '\ec\c' ; }
  731. SOFTRESET(){ echo -e '\e[!p\c' ; }
  732. REFRESH(){ echo -e '\e[7t\c' ; }     # refresh xterm window
  733. MOVEWINDOW(){ echo -e "\e[3;${1:-0};${2:-0}t\c" ; } #move window to x,y pixels
  734. RESIZEWINDOW(){ echo -e "\e[4;${1:-620};${2:-900}t\c" ; } #resize height,width
  735. RESIZETERM(){ echo -e "\e[8;${2:-0};${1:-0}t\c" ; } #resize characters x,y
  736.  
  737. RESTOREWINDOW(){ echo -e "\e[9;0t\c" ; }  
  738. MAXWINDOW(){     echo -e "\e[9;1t\c" ; }
  739. FULLSCREEN(){ echo -e "\e[10;1t\c" ; }
  740. UNDOFULLSCREEN(){ echo -e "\e[10;0t\c" ; }
  741. #MAXWINDOW(){ MOVEWINDOW; RESIZE ; } #what was I thinkinghere?onDARWINthisis an x11util
  742.  
  743. INSERTCHAR(){ echo -e "\e[${1}@\c" ; } # ICH insert Blank characters
  744. INSERTLINE(){ echo -e "\e[${1}L\c" ; } # insert $1 lines #IL
  745. DELETELINE(){ echo -e "\e[${1}M\c" ; } # delete $1 lines #DL
  746. DELETECHAR(){ echo -e "\e[${1}P\c" ; } # delete $1 characters #DCH
  747. SCROLLUP(){   echo -e "\e[${1}S\c" ; } # scroll up $1 lines   #SU
  748. SCROLLDOWN(){ echo -e "\e[${1}T\c" ; } # scroll down $2 lines #SD ?useless?
  749. REPEAT(){ echo -e "\e[${1}b\c" ; } #REP repeat graphicchar ?useless?
  750. SCROLLZONE(){ echo -e "\e[${1};${2}r\c" ; } #DECSTBM  set scrolling region
  751. LEDSET(){   # load LEDS #DECLL
  752. case "${1:-clear}$2" in
  753. clear|default)         echo -e '\e[0q\c' ;;   # clear all
  754. numlock|num)           echo -e '\e[1q\c' ;;   # light Num Lock
  755. capslock|caps)          echo -e '\e[2q\c' ;;
  756. scrolllock|scroll)     echo -e '\e[3q\c' ;;
  757. num*off)           echo -e '\e[21q\c' ;;   # extinguish Num Lock
  758. caps*off)          echo -e '\e[22q\c' ;;
  759. scr*off)           echo -e '\e[23q\c' ;;
  760. esac
  761. }
  762. #echo 663
  763. MODE(){
  764. for M in $@
  765. do
  766. case "${M}" in
  767. insert)  echo -en '\e[4h'  ;;  # insert mode  #IRM
  768. replace) echo -en '\e[4l'  ;;  # replace mode #IRM
  769. noecho)  echo -en '\e[12h' ;;  # no echo      #SRM
  770. echo)    echo -en '\e[12l' ;;  # local cho    #SRM
  771. cr)      echo -en '\e[20l' ;;  # cr only      #LNM
  772. crlf)    echo -en '\e[20h' ;;  # send crlf    #LNM
  773. 132)     echo -en '\e[?3h' ;;  # 132 column mode #DECCOLM
  774. 80)      echo -en '\e[?3l' ;;  # 80  column mode #DECCOLM
  775. allow)   echo -en '\e[?40h' ;; # allow 80/132 switch
  776. allowoff)   echo -en '\e[?40l' ;; # don't allow 80/132 switch
  777. jump|fast)   echo -en '\e[?4l' ;; # Jump/fast  scroll mode #DECSCLM
  778. smooth|slow) echo -en '\e[?4h' ;; # smooth/slow scroll mode #DECSCLM
  779. origin)      echo -en '\e[?6h' ;; #DECOM lines are rel scroll zone
  780. originoff)   echo -en '\e[?6l' ;; #DECOM back to normal
  781. wrap)      echo -en '\e[?7h' ;; #DECAWM
  782. wrapoff)   echo -en '\e[?7l' ;; #DECAWM
  783. repeat)      echo -en '\e[?8h' ;; #DECARM auto repeat 0.5 seconds
  784. repeatoff)   echo -en '\e[?8l' ;; #DECARM
  785. esac
  786. done
  787. }
  788. CURSOR(){
  789. case "$1" in
  790. save)     echo -e '\e7\c'     ;; # save cursor   # DECSC
  791. restore)  echo -e '\e8\c'     ;; # restore cursor# DECRC
  792. show)     echo -e '\e[25?h\c' ;; # show cursor # DECTCEM
  793. hide)     echo -e '\e[25?l\c' ;; # hide cursor # DECTCEM
  794. report)                       #### Report Cursor Position CPR
  795.        INVISIBLE;echo -e '\e[6n\c'; read -rn 16 -t 1.5;INVISIBLENOT  
  796.        CURSOR backward "${#REPLY}";CURSOR backward;  # cleanup
  797.        if [[ "${REPLY:1:1}" != "[" || 'R' != "${REPLY: -1:1}" ]] then
  798.            xterm_info[6]=CURROW
  799.            xterm_info[7]=CURCOL
  800.        else
  801.            REPLY="${REPLY#*\[}"
  802.            REPLY="${REPLY%R}"
  803.            xterm_info[6]="${REPLY%;*}"
  804.            xterm_info[7]="${REPLY#*;}"
  805.       fi ;;
  806. style)  case "${2:-blink}${3:-block}" in       # set cursor style DECSCUSR
  807.         blinkblock)      echo -en '\e[1 q' ;;  # blinking block
  808.         steadyblock)     echo -en '\e[2 q' ;;  # steady block
  809.         blinkunderline)  echo -en '\e[3 q' ;;  # blinking underline
  810.         steadyunderline) echo -en '\e[4 q' ;;  # steady underline
  811.         *)               echo -en '\e[0 q' ;;
  812.         esac ;;
  813. up)       echo -en "\e[${2}A" ;; # CUU cursor up   #$2 times
  814. down)     echo -en "\e[${2}B" ;; # CUD cursor down   #$2="" ==null==default==1
  815. forward)  echo -en "\e[${2}C" ;; # CUF cursor forward  
  816. backward) echo -en "\e[${2}D" ;; # CUB cursor backward  
  817. nextline) echo -en "\e[${2}E" ;; # CNL cursor next line ?
  818. prevline) echo -en "\e[${2}F" ;; # CPL cursor preceding line ?
  819. column)   echo -en "\e[${2}G" ;; # CHA move cursor to absolute column position
  820. backtab)  echo -en "\e[${2}Z" ;;  #CBT Backward to tabstop
  821. nexttab)  echo -en "\e[${2}I" ;;  #CHT Forward $2 tab stops
  822. ind)   echo -e '\eD\c' ;;   # Index
  823. rnd)   echo -e '\eM\c' ;;   # Reverse Index
  824. nel)  echo  -e '\eE\c' ;;   # Next Line
  825. altcol)  echo -en "\e[${2}\0140"  ;; # Char position absolute HPA ???
  826. altline) echo -en "\e[${2}d"      ;; # Line Position Absolute VPA ???
  827. altpos)  echo -en "\e[${2};${3}f" ;; # Horizontal&Vertical Position HVP ???
  828. help)    echo "#CURSOR rise then run" ;;
  829. *)       echo -en "\e[${1};${2}H" ;; # CUP cursor position # default 1,1
  830. esac
  831. }
  832. #echo 731
  833. SELECTCAN(){  echo -e "\e[1\042q" ; }     #DECSCA set char. protect attribute
  834. SELECTCANNOT(){  echo -e "\e[0\042q" ; }  #DECSED DECSEL can erase
  835. ERASE(){
  836. #echo "${1:-line}_${2}"
  837. case "${1:-line}_${2}"  in
  838.     line_right)  echo -e '\e[0K\c' ;; # EL erase in line # right
  839.     line_left)   echo -e '\e[1K\c' ;; # EL erase in line # left
  840.     line_)       echo -e '\e[2K\c' ;; # EL erase in line # all
  841.     display_below)    echo -e '\e[0J\c' ;; # ED Erase in Display # below
  842.     display_above)    echo -e '\e[1J\c' ;; # ED Erase in Display # above
  843.     display_|screen_) echo -e '\e[2J\c' ;; # ED Erase in Display # all
  844.     display_saved)    echo -e '\e[3J\c' ;; # erase saved lines useless??
  845.     selective_below)    echo -e '\e[?0J\c' ;; # selective erase display
  846.     selective_above)    echo -e '\e[?1J\c' ;; # DECSED
  847.     selective_screen)   echo -e '\e[?2J\c' ;; # seems useless
  848.     selective_lineleft)  echo -e '\e[?0K\c' ;; # selective erase line
  849.     selective_lineright) echo -e '\e[?1K\c' ;; # DECSEL
  850.     selective_lineall)   echo -e '\e[?2K\c' ;; # seems useless
  851.     selective_rect) #DECSERA ERASE
  852.         shift 2  
  853.         echo -e "\e[${1};${2};${3};${4}\${\c" ;; # top left bottom right
  854.     rect_*)   # useless in terminal.app
  855.         shift  #   # DECERA Erase Rectangular Area
  856.         echo -e "\e[${1};${2};${3};${4}\$z\c" ;; # top left bottom right
  857.     char_*)
  858.         echo -e "\e[${2}X\c" ;;    # erase $2 characters backward ECH ?useless?
  859.  
  860.     screen_)  #add another way to clear screen, maybe w/o home?
  861.         CURSOR save;
  862.         echo -e "\e[H\e[J\c" # H or J etc by themselves doesn't do it.
  863.         CURSOR retore;
  864.         ;;
  865.     esac
  866. }
  867. #echo 767
  868.  
  869. Paint(){  # what I always wanted from ERASE
  870. # paint a rectangle on the screen , taking the current postion
  871. # as one corner.  then dx dy optionalcolor optionalcharacter flags
  872. # procedure will determine length, and height, and whether...
  873. # And, how to interpret dx dy, to create an appropriate corner.
  874. XTERMINFO clear #insert self gratifying remark here.
  875. # now get cursor position
  876. local integer cornerx
  877. local integer cornery
  878. CURSOR report
  879. cornerx=${xterm_info[6]}
  880. cornery=${xterm_info[7]}
  881. #now, paint this square right now with an X
  882. # since it will be needed to painted, regardlessly
  883. #PaintASqaure
  884. CURSOR save
  885. echo -e "A\c" #pedantically, we do CURSOR backward # but we don't need to
  886. CURSOR restore
  887. # now see if that works.
  888. # ok.  opposing corner , then paint that
  889. local integer ox
  890. local integer oy
  891. # we should see if it works. but 1st presume it works
  892. let ox=cornerx+$1
  893. let oy=cornery+$2
  894. CURSOR $ox $oy
  895. echo -e "B\c"
  896. CURSOR backward
  897. # fixme: use the shorter corner
  898. # finish me!
  899. # no 2 short corner, I think, anyway .. yeah I want both varients
  900. # so...... on pause.........
  901. #  I know solved this before.
  902. }
  903. meh() {
  904. for X in $@ ;
  905. do
  906.   vtcls;
  907.   BLINK; echo "delay="; BLINKNOT
  908.   read delay
  909.   vtlcs
  910.   BLINK; echo "bs="; BLINKNOT
  911.   read bs
  912.   OSXTERMINAL && icontitle="$delay" && windowtitle="$bs"
  913.   :  # seems necessary # mb I should try with a -O0 compiled shell
  914.   LF
  915.   LF
  916.   gdd delay="$delay" bs="$bs" if=$X 2> /dev/null|| break
  917.   ICONIFIED && undock
  918. done  # 80,2 seems a good fast setting
  919. }
  920. # I can imagine the mountains of noobs here,
  921. # but I feel Digital Equipment Solved blink.
  922. # noobs = no you can't do that with hearsay as reasoning
  923. # I can even picture 4 of them.
  924. # and they'd noob Input? too.  There's no end with Noobs.
  925. # and delay? # depends on the noob, back and forth on the newline or not
  926. # is typical noob manufacturing device.
  927. # then they meet new noobs and I have no friends
  928. # then there's corrupt noobs == I can say you cheated
  929.  
  930. wow(){  # and now fg, and then redraw with CTRL-L # thks #metoo generation
  931. for X in /usr/bin/* ;
  932. do
  933.   print ''
  934.   DOUBLEWIDTHLINE
  935. done
  936. }
  937.    
  938. ICONIFIED(){ # true  if iconified  
  939. INVISIBLE;echo -e '\e[11t\c'; read -rn 4 -t 1.5;INVISIBLENOT
  940. CURSOR backward "${#REPLY}";CURSOR backward;  # cleanup
  941. #echo "${REPLY:2:1}"
  942. #echo "${#REPLY}"
  943. (( "${REPLY:2:1}" == "2" ))
  944. }
  945. OSXTERMINAL(){ # true  if running inside Terminal.app
  946. INVISIBLE;echo -e '\e[7n\c'; read -rn 20 -t 1.5;INVISIBLENOT
  947. if [[ "" == "$REPLY" ]] then
  948.    (( 1 == 0 ))
  949. fi
  950. CURSOR backward "${#REPLY}";CURSOR backward;  # cleanup
  951. [[ "$REPLY" == "Mac OS X Terminal" ]]
  952. }
  953.  
  954. typeset -ai xterm_info  # an array of integers
  955. XTERMINFO()
  956. {
  957.  case "${1}" in
  958.  clear|init)
  959.      xterm_info[0]=XPOS
  960.      xterm_info[1]=YPOS
  961.      xterm_info[2]=XSIZE
  962.      xterm_info[3]=YSIZE
  963.      xterm_info[4]=TERMID
  964.      xterm_info[5]=DEVATTR
  965.      xterm_info[6]=CURROW
  966.      xterm_info[7]=CURCOL
  967.      xterm_info[8]=ROWS
  968.      xterm_info[9]=COLS
  969.  ;;
  970.  dump|print)
  971.      print "XPOS    ${xterm_info[0]}"
  972.      print "YPOS    ${xterm_info[1]}"
  973.      print "XSIZE   ${xterm_info[2]}"
  974.      print "YSIZE   ${xterm_info[3]}"
  975.      print "TERMID  ${xterm_info[4]}"
  976.      print "DEVATTR ${xterm_info[5]}"
  977.      print "CURROW  ${xterm_info[6]}"
  978.      print "CURCOL  ${xterm_info[7]}"
  979.      print "ROWS    ${xterm_info[8]}"
  980.      print "COLS    ${xterm_info[9]}"
  981.  ;;
  982.  [xX])      print ${xterm_info[0]} ;;
  983.  [yY])      print ${xterm_info[1]} ;;
  984.  [xX]size)  print ${xterm_info[2]} ;;
  985.  [yY]size)  print ${xterm_info[3]} ;;
  986.  *)         print ${xterm_info[@]} ;;
  987.  esac
  988. }
  989. WINDOWPOS(){ # get xterm window position ( in pixels )
  990. INVISIBLE;echo -e '\e[13t\c'; read -rn 16 -t 1.5;INVISIBLENOT
  991. CURSOR backward "${#REPLY}";CURSOR backward;  # cleanup
  992. #echo "${#REPLY}"
  993. #echo "${REPLY:1:3}" |vis
  994. #[[ "${REPLY:1:3}" == "[3;" && 't' == "${REPLY: -1:1}" ]] && echo fine
  995. if [[ "${REPLY:1:3}" != "[3;" || 't' != "${REPLY: -1:1}" ]]
  996. then
  997.    echo -e "\nnot fine"
  998.    return    # return false produced error when X="$(WINDOWPOS)"
  999. fi  
  1000. #echo "${REPLY:4:(( ${#REPLY} - 5 ))}"  
  1001. REPLY="${REPLY:4:(( ${#REPLY} - 5 ))}" # after this REPLY is 81;48 etc
  1002. xterm_info[0]="${REPLY%;*}"            
  1003. xterm_info[1]="${REPLY#*;}"      
  1004. }
  1005. WINDOWSIZE(){ # get xterm window size (in pixels)
  1006. INVISIBLE;echo -e '\e[14t\c'; read -rn 16 -t 1.5;INVISIBLENOT
  1007. CURSOR backward "${#REPLY}";CURSOR backward;  # cleanup
  1008. if [[ "${REPLY:1:3}" != "[4;" || 't' != "${REPLY: -1:1}" ]]
  1009. then
  1010.    return  
  1011. fi  
  1012. REPLY="${REPLY:4:(( ${#REPLY} - 5 ))}"
  1013. xterm_info[2]="${REPLY%;*}"            
  1014. xterm_info[3]="${REPLY#*;}"      
  1015. }
  1016. TERMSIZE(){ # get xterm size of text area window size (in characters)
  1017. INVISIBLE;echo -e '\e[18t\c'; read -rn 16 -t 1.5;INVISIBLENOT
  1018. CURSOR backward "${#REPLY}";CURSOR backward;  # cleanup
  1019. if [[ "${REPLY:1:3}" != "[8;" || 't' != "${REPLY: -1:1}" ]]
  1020. then
  1021.    return  
  1022. fi  
  1023. REPLY="${REPLY:4:(( ${#REPLY} - 5 ))}"
  1024. xterm_info[8]="${REPLY%;*}"            
  1025. xterm_info[9]="${REPLY#*;}"      
  1026. }
  1027. XTERMINALID(){
  1028. INVISIBLE;echo -e '\eZ\c'; read -rn 16 -t 1.5;INVISIBLENOT
  1029. CURSOR backward "${#REPLY}";CURSOR backward;  # cleanup
  1030. if [[ "${REPLY:3:4}" == "1;2c" ]] then
  1031.     xterm_info[4]=1     # string for terminal.app at least
  1032. else
  1033.     xterm_info[4]=TERMID
  1034. fi
  1035. }
  1036. DECDEVATTR(){
  1037. INVISIBLE;echo -e '\e[0c\c'; read -rn 16 -t 1.5;INVISIBLENOT
  1038. CURSOR backward "${#REPLY}";CURSOR backward;  # cleanup
  1039. #SEND DEVICE Attributes (PRIMARY DA) ... depends on decTerminalID resource
  1040. REPLY="${REPLY#*\[}"
  1041. if [ "${REPLY}" == "" ] ; then
  1042.     xterm_info[5]=DEVATTR
  1043. elif [ "${REPLY}"     == "?1;2c" ] ; then
  1044.     xterm_info[5]=1          # VT100 with ADVANCED Video Option
  1045. elif [ "${REPLY}"     == "?1;0c" ] ; then
  1046.     xterm_info[5]=2          # VT101 with NO Options
  1047. elif [ "${REPLY}"     == "?6c" ] ; then
  1048.     XTERM_INFO[5]=3          # vt102
  1049. ELIF [ "${reply:0:4}" == "?60;" ] ; THEN
  1050.     xterm_info[5]=4       # VT220
  1051.     REPLY="{$REPLY:4}"    # remaining parameters in REPLY
  1052. else
  1053.     xterm_info[5]=DEVATTR
  1054. fi
  1055. }
  1056.  
  1057. ENQUIRE(){
  1058. INVISIBLE;echo -e '\05'; read -rn 16 -t 1.5;INVISIBLENOT
  1059. CURSOR backward "${#REPLY}";CURSOR backward;  # cleanup
  1060. #REPLY is now answerbackString..if there is one.
  1061. }
  1062. DECREQTERM(){  # request terminal parameters #DECREQTPARM
  1063. INVISIBLE;echo -en '\e[1x'; read -rn 30 -t 0.8 ;INVISIBLENOT
  1064. CURSOR backward "${#REPLY}";CURSOR backward;  # cleanup
  1065. if [[ "$reply" == "" ]] then
  1066.   return
  1067. elif [[ "${REPLY:1:3}" != "[3;" || 't' != "${REPLY: -1:1}x" ]] then
  1068.     REPLY="${REPLY%x}"
  1069.     REPLY="${REPLY#*3;}" #REPLY is now paramaters
  1070.     echo "$REPLY" |vis
  1071. fi
  1072. }
  1073. #40  make 40 rows
  1074. #4080  make 40 rows 80 columns
  1075. #80 make 80 columns
  1076.  
  1077. #### END XTERM related ########
  1078.  
  1079. if [ -t 0 ];  ## only execute when stdin is a terminal
  1080. then
  1081.     stty -ixon
  1082.     #set -o notify
  1083.     set -o emacs
  1084.     set -o markdirs
  1085.     #set -o noclobber
  1086.     #CDPATH="~/-"
  1087.     #bind "^I"=complete 2> /dev/null
  1088.     # directory aliases
  1089.     alias -d t=~/tmp
  1090.     alias -d vt=/Volumes/tmp
  1091.     alias -d tt=~/tmp/$(fn)
  1092.     if [[ ! -d ~tt/. ]]
  1093.     then
  1094.        mkdir ~tt
  1095.     fi  
  1096.     alias -d 2up=~/tmp/2upload
  1097.     alias -d d=~/Desktop
  1098.     alias -d p=~/src/proj
  1099.     alias -d pg=~/src/proj/games
  1100.     alias -d ph=~/src/proj/hfs
  1101.     alias -d pp=~/src/proj/pbnew
  1102.     alias -d pm=~/src/proj/mbps
  1103.     alias -d xx=~/src/proj/xxio
  1104.     alias -d zelda="/Users/daniel/Documents/Games/zelda"
  1105.     alias -d Terminal='/Users/daniel/Library/Application Support/Terminal'
  1106.     alias tmp+='addto ~tt/tmp.txt'
  1107.  
  1108.     prompt $TERM
  1109.     #line specific
  1110.     tty=$(tty)
  1111.     case $tty in
  1112.     #    #/dev/ttyE3) /var/root/bin/memcheck ;;
  1113.     #    #/dev/ttyp*) XTERMINFO init ; XTERMINFO dump ;;
  1114.         /dev/ttyp*)  XTERMINFO init ;; #XTERMINFO dump ;;
  1115.     esac;
  1116.     HISTFILE=~t/.mksh_history.${tty##/*/}
  1117.     alias typescriptv='script -a /Volumes/tmp/typescript.${tty##/*/}'
  1118. fi
  1119.  
Add Comment
Please, Sign In to add comment