Home | History | Annotate | Download | only in mksh
      1 # Copyright (c) 2010, 2012, 2013, 2014
      2 #	Thorsten Glaser <tg (a] mirbsd.org>
      3 # This file is provided under the same terms as mksh.
      4 #-
      5 # Minimal /system/etc/mkshrc for Android
      6 #
      7 # Support: https://launchpad.net/mksh
      8 
      9 : ${TERM:=vt100} ${HOME:=/data} ${MKSH:=/system/bin/sh} ${HOSTNAME:=$(getprop ro.product.device)}
     10 : ${SHELL:=$MKSH} ${USER:=$(typeset x=$(id); x=${x#*\(}; print -r -- ${x%%\)*})} ${HOSTNAME:=android}
     11 if (( USER_ID )); then PS1='$'; else PS1='#'; fi
     12 PS4='[$EPOCHREALTIME] '; PS1='${|
     13 	local e=$?
     14 
     15 	(( e )) && REPLY+="$e|"
     16 
     17 	return $e
     18 }$USER@$HOSTNAME:${PWD:-?} '"$PS1 "
     19 export HOME HOSTNAME MKSH SHELL TERM USER
     20 alias l='ls'
     21 alias la='l -a'
     22 alias ll='l -l'
     23 alias lo='l -a -l'
     24 
     25 function hd {
     26 	local -Uui16 -Z11 pos=0
     27 	local -Uui16 -Z5 hv=2147483647
     28 	local dasc line i
     29 
     30 	cat "$@" | { set +U; if read -arN -1 line; then
     31 		typeset -i1 line
     32 		i=0
     33 		while (( i < ${#line[*]} )); do
     34 			hv=${line[i++]}
     35 			if (( (pos & 15) == 0 )); then
     36 				(( pos )) && print -r -- "$dasc|"
     37 				print -n "${pos#16#}  "
     38 				dasc=' |'
     39 			fi
     40 			print -n "${hv#16#} "
     41 			if (( (hv < 32) || (hv > 126) )); then
     42 				dasc+=.
     43 			else
     44 				dasc+=${line[i-1]#1#}
     45 			fi
     46 			(( (pos++ & 15) == 7 )) && print -n -- '- '
     47 		done
     48 		while (( pos & 15 )); do
     49 			print -n '   '
     50 			(( (pos++ & 15) == 7 )) && print -n -- '- '
     51 		done
     52 		(( hv == 2147483647 )) || print -r -- "$dasc|"
     53 	fi; }
     54 }
     55 
     56 function more {
     57 	(
     58 		set +m
     59 		cat "$@" |&
     60 		trap "rv=\$?; kill $! >/dev/null 2>&1; exit \$rv" EXIT
     61 		while IFS= read -pr line; do
     62 			llen=${%line}
     63 			(( llen == -1 )) && llen=${#line}
     64 			(( llen = llen ? (llen + COLUMNS - 1) / COLUMNS : 1 ))
     65 			if (( (curlin += llen) >= LINES )); then
     66 				print -n -- '\033[7m--more--\033[0m'
     67 				read -u1 || exit $?
     68 				[[ $REPLY = [Qq]* ]] && exit 0
     69 				curlin=$llen
     70 			fi
     71 			print -r -- "$line"
     72 		done
     73 	)
     74 }
     75 
     76 function setenv {
     77 	eval export "\"$1\""'="$2"'
     78 }
     79 
     80 for p in ~/.bin; do
     81 	[[ -d $p/. ]] || continue
     82 	[[ :$PATH: = *:$p:* ]] || PATH=$p:$PATH
     83 done
     84 
     85 unset p
     86 
     87 : place customisations above this line
     88