]> git.phdru.name Git - dotfiles.git/blob - .shellrc
.shellrc: Move bash-only code to `.bashrc`
[dotfiles.git] / .shellrc
1 #
2 # $HOME/.shellrc
3 #
4
5 # If not running interactively, don't do anything
6 case $- in
7     *i*) ;;
8       *) return ;;
9 esac
10
11 # Stop if non-interactive shell
12 [ -z "$PS1" ] && return
13
14 #if [ -x /usr/bin/dircolors ]; then
15 #   # I don't like these aliases - they work only in command line
16 #   # but not in scripts I run from command line.
17 #   # Color parameters must be passed via environment.
18 #   # So instead I put them in shell scripts in ~/bin.
19 #   alias ls='ls --color=auto'
20 #   alias dir='dir --color=auto'
21 #   alias vdir='vdir --color=auto'
22 #
23 #   alias grep='grep --color=auto'
24 #   alias fgrep='fgrep --color=auto'
25 #   alias egrep='egrep --color=auto'
26 #
27 #   alias dmesg='dmesg --human'
28 #fi
29
30
31 case "$HOME" in
32     /home/*)
33         if [ -L /home ]; then
34             START_DIR="`pwd`" &&
35             cd "$HOME" &&
36             HOME="`pwd`" &&
37             cd "$START_DIR"
38         fi
39     ;;
40 esac
41
42 if test -n "$KSH_VERSION" -o -n "$FCEDIT"; then
43     back() { cd - "$@"; }
44     j() { jobs; }
45 fi
46
47 # clear screen and history, logout
48 chlo() { clear; cd; >$HISTFILE; unset HISTFILE; history -c; logout || exit; }
49
50
51 include() {
52     cfg="$1"
53     shift
54     if [ -f "./$cfg" -a -r "./$cfg" ]; then
55         echo "Reading config file \`$cfg'" 1>&2
56         . "./$cfg" "$@"
57     elif [ -f "$HOME/lib/config/$cfg" -a -r "$HOME/lib/config/$cfg" ]; then
58         echo "Reading config file \`$HOME/lib/config/$cfg'" 1>&2
59         . "$HOME/lib/config/$cfg" "$@"
60     else
61         echo "Cannot find config file \`$cfg'" 1>&2
62     fi
63 }
64
65
66 [ "`type -t mc`" = alias ] && unalias mc
67 mc() {
68     if [ -n "$SLOWTERM" ]; then
69         MC_SLOW="--slow"
70     fi
71
72     case "$TERM" in
73         screen*) # screen, screen.rxvt
74             MC_XTERM="-x"
75         ;;
76     esac
77
78     #TMPDIR="$HOME"/tmp
79     #export TMPDIR
80
81     MC_FOUND=NO
82
83     for wrapper in \
84             /usr/local/share/mc/bin/mc-wrapper.sh \
85             /usr/local/libexec/mc/mc-wrapper.sh \
86             /usr/share/mc/bin/mc-wrapper.sh; do
87         if [ -r $wrapper ]; then
88             . $wrapper $MC_SLOW $MC_XTERM "$@"
89             rc=$?
90             MC_FOUND=YES
91             break
92         fi
93     done
94
95     if [ $MC_FOUND = NO ]; then
96         for mc in /usr/local/bin/mc /usr/bin/mc; do
97             if [ -x $mc ]; then
98                 MC_TMP_DIR="${TMPDIR-/tmp}/mc-$USER"
99                 if [ ! -d MC_TMP_DIR="${TMPDIR-/tmp}/mc-$USER" ]; then
100                     MC_TMP_DIR="${TMPDIR-/tmp}"
101                 fi
102                 MC_PWD_FILE="$MC_TMP_DIR/mc.pwd.$$"
103                 mc_type="`mc_type.py $mc`"
104                 if [ "$mc_type" = old ]; then
105                     $mc -P $MC_SLOW $MC_XTERM "$@" > "$MC_PWD_FILE"
106                 elif [ "$mc_type" = new ]; then
107                     $mc -P "$MC_PWD_FILE" $MC_SLOW $MC_XTERM "$@"
108                 else
109                     continue
110                 fi
111                 rc=$?
112                 MC_FOUND=YES
113                 cd "`cat \"$MC_PWD_FILE\"`" && /bin/rm "$MC_PWD_FILE"
114                 break
115             fi
116         done
117     fi
118
119     if [ $MC_FOUND = NO ]; then
120         echo "Cannot find mc-wrapper.sh or mc" >&2
121         rc=1
122     fi
123
124     unset MC_FOUND MC_PWD_FILE MC_SLOW MC_TMP_DIR MC_XTERM
125
126     return $rc
127 }
128
129
130 mkcd() {
131     if [ $# -ne 1 ]; then
132         echo "Usage: mkcd directory_name" >&2
133     elif [ -d "$1" ]; then
134         cd "$1"
135     elif [ -e "$1" ]; then
136         echo "Error: $1 is a file" >&2
137     else
138         mkdir -p "$1" && cd "$1"
139     fi
140 }
141
142
143 if which tmux >/dev/null 2>&1; then
144     tmux() {
145         case "$TERM" in
146             rxvt)
147                 TERM=rxvt-unicode command tmux "$@"
148             ;;
149
150             *)
151                 command tmux "$@"
152             ;;
153         esac
154     }
155 fi
156
157
158 vim() {
159     command vim "$@"
160     rc=$?
161     cd "`cat \"$HOME/tmp/vim/cwd\"`" && /bin/rm "$HOME/tmp/vim/cwd" &&
162     return $rc
163 }
164
165
166 if [ "$SHLVL" -eq 1 ] && which startx >/dev/null 2>&1; then
167     X() { startx >> .Xserver.log 2>&1; cyr; /bin/rm -f .Xauthority; }
168 fi
169
170 x() { exit; }