-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.kshrc
124 lines (107 loc) · 3.4 KB
/
.kshrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# tty
# ----------------------------------------------------------------------------
stty -ixon
# ksh variables
# ----------------------------------------------------------------------------
PATH=~/.scripts:$PATH
# history
HISTFILE=~/.ksh_history
HISTCONTROL=ignoredups:ignorespace
# editor
export VISUAL=nano
export EDITOR=nano
# environment variables
# ----------------------------------------------------------------------------
# key bindings
# ----------------------------------------------------------------------------
if [[ $TERM == st-256color ]]; then
# Ctrl-Delete
bind '^[[3;5~'=delete-word-forward
fi
# alias
# ----------------------------------------------------------------------------
alias -- 1='fg %1'
alias -- 2='fg %2'
alias -- 3='fg %3'
alias -- 4='fg %4'
alias -- 5='fg %5'
alias -- 6='fg %6'
alias -- 7='fg %7'
alias -- 8='fg %8'
alias -- 9='fg %9'
alias -- 0='fg %10'
alias -- -='fg %-'
alias -- +='fg %+'
# prompts
# ----------------------------------------------------------------------------
# disable python virtual environment's default prompt
export VIRTUAL_ENV_DISABLE_PROMPT=true
# count the number of sh stacks in PS1
export __SH_INTERACTIVE_STACKS=$(($__SH_INTERACTIVE_STACKS + 1))
__ps() {
local es=$?
# wrap the format code within '\[' and '\]' to avoid prompt issues
# when scrolling through command histories. Find more:
# - https://superuser.com/a/980982
# - http://tldp.org/HOWTO/Bash-Prompt-HOWTO/nonprintingchars.html
local ANSI_END='\[\e[0m\]'
local ANSI_BOLD='\[\e[1m\]'
local ANSI_ITALIC='\[\e[3m\]'
local ANSI_REVERSE='\[\e[7m\]'
local ANSI_BLACK='\[\e[90m\]'
local ANSI_RED='\[\e[91m\]'
local ANSI_GREEN='\[\e[92m\]'
local ANSI_YELLOW='\[\e[93m\]'
local ANSI_BLUE='\[\e[94m\]'
local ANSI_BLUE2='\[\e[3;49;90m\]'
local ANSI_MAGENTA='\[\e[95m\]'
local ANSI_CYAN='\[\e[96m\]'
local ANSI_WHITE='\[\e[97m\]'
case "$1" in
1) # line 1
echo -n "${ANSI_BOLD}.--==${ANSI_END} "
# python virtual environment
if [[ -n ${VIRTUAL_ENV} ]]; then
echo -n "(${VIRTUAL_ENV}) "
fi
echo -n "${ANSI_BOLD}${ANSI_RED}\u@\h${ANSI_END} "
echo -n "at ${ANSI_BOLD}${ANSI_BLUE}\\\t${ANSI_END} "
echo -n "in ${ANSI_BOLD}${ANSI_YELLOW}\w${ANSI_END} "
# TODO: show git status
#PS1+="${ANSI_GREEN}$(__git_ps1)${ANSI_END}"
echo -n "\n"
# line 2
echo -n "${ANSI_BOLD}· ${ANSI_END} "
echo -n "${ANSI_BOLD}${ANSI_BLACK}$(tty)${ANSI_END}"
echo -n "${ANSI_BOLD}${ANSI_BLACK} | exit $es${ANSI_END}"
if (( ${__SH_INTERACTIVE_STACKS} > 1 )); then
echo -n "${ANSI_BOLD}${ANSI_BLACK} | ${ANSI_REVERSE}sh ${__SH_INTERACTIVE_STACKS}${ANSI_END}"
else
echo -n "${ANSI_BOLD}${ANSI_BLACK} | ksh ${__SH_INTERACTIVE_STACKS}${ANSI_END}"
fi
if (( $(jobs -p | wc -l) > 0 )); then
echo -n "${ANSI_BOLD}${ANSI_BLACK} | ${ANSI_REVERSE}job No.\j${ANSI_END}"
else
echo -n "${ANSI_BOLD}${ANSI_BLACK} | job \j${ANSI_END}"
fi
echo -n "${ANSI_BOLD}${ANSI_BLACK} | history No.\!${ANSI_END}"
echo -n "${ANSI_BOLD}${ANSI_BLACK} | command No.\#${ANSI_END}"
echo -n "\n"
# line 3
echo -n " ${ANSI_BOLD}\`--=== ${ANSI_GREEN}\$${ANSI_END} "
;;
2) echo -n " ${ANSI_BOLD}\`--=== ${ANSI_GREEN}>${ANSI_END} "
;;
esac
}
PS1='$(__ps 1)'
PS2=$(__ps 2)
# customized settings depending on systems
# ----------------------------------------------------------------------------
case $(uname) in
Linux ) export LC_ALL=C.UTF-8
;;
OpenBSD ) # UTF-8 are partially supported
export LC_CTYPE=C
;;
esac