OSDN Git Service

Merge "Update to mksh R48"
[android-x86/external-mksh.git] / mkshrc
1 # Copyright (c) 2010, 2012, 2013
2 #       Thorsten Glaser <tg@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         local dummy line llen curlin=0
58
59         cat "$@" | while IFS= read -r line; do
60                 llen=${%line}
61                 (( llen == -1 )) && llen=${#line}
62                 (( llen = llen ? (llen + COLUMNS - 1) / COLUMNS : 1 ))
63                 if (( (curlin += llen) >= LINES )); then
64                         print -n -- '\033[7m--more--\033[0m'
65                         read -u1 dummy
66                         [[ $dummy = [Qq]* ]] && return 0
67                         curlin=$llen
68                 fi
69                 print -r -- "$line"
70         done
71 }
72
73 function setenv {
74         eval export "\"$1\""'="$2"'
75 }
76
77 for p in ~/.bin; do
78         [[ -d $p/. ]] || continue
79         [[ :$PATH: = *:$p:* ]] || PATH=$p:$PATH
80 done
81
82 unset p
83
84 : place customisations above this line