]> git.phdru.name Git - dotfiles.git/blob - .shellrc
.bashrc,.profile,.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 if test -n "$BASH_VERSION" -a -z "$MC_SID"; then
48    if [ -r "$HOME"/admin/prog/bash_prompt ]; then
49       . "$HOME"/admin/prog/bash_prompt
50       set_prompts
51       unset set_prompts
52    else
53       OPS1="${debian_chroot:+($debian_chroot)}\u@\h:\W \$SHLVL\\$ "
54    fi
55 fi
56
57 PS1="$OPS1"
58
59 # clear screen and history, logout
60 chlo() { clear; cd; >$HISTFILE; unset HISTFILE; history -c; logout || exit; }
61
62
63 include() {
64    cfg="$1"
65    shift
66    if [ -f "./$cfg" -a -r "./$cfg" ]; then
67       echo "Reading config file \`$cfg'" 1>&2
68       . "./$cfg" "$@"
69    elif [ -f "$HOME/lib/config/$cfg" -a -r "$HOME/lib/config/$cfg" ]; then
70       echo "Reading config file \`$HOME/lib/config/$cfg'" 1>&2
71       . "$HOME/lib/config/$cfg" "$@"
72    else
73       echo "Cannot find config file \`$cfg'" 1>&2
74    fi
75 }
76
77
78 mc() {
79    if test -n "$BASH_VERSION"; then
80       MC_SAVE_OPS1="$OPS1"
81       if [ "`type -t short_curdir`" = function ]; then
82          OPS1="\`cgmem_which_prompt\`\u@\${HOSTNAME::5}:\`short_curdir\`"
83          if test -x /usr/bin/git >/dev/null 2>&1; then
84             #if [ "`type -t __git_ps1`" = function ]; then
85             #   OPS1+="\$(__git_ps1)"
86             #else
87                OPS1+="\$(prompt_git)"
88             #fi
89          fi
90          OPS1+=" \$SHLVL\\$ "
91       else
92          OPS1="\u@\h:\W \$SHLVL\\$ "
93       fi
94    fi
95
96    if [ -n "$SLOWTERM" ]; then
97       MC_SLOW="--slow"
98    fi
99
100    case "$TERM" in
101       screen*) # screen, screen.rxvt
102          MC_XTERM="-x"
103       ;;
104    esac
105
106    #TMPDIR="$HOME"/tmp
107    #export TMPDIR
108
109    MC_FOUND=NO
110
111    for wrapper in \
112          /usr/local/share/mc/bin/mc-wrapper.sh \
113          /usr/local/libexec/mc/mc-wrapper.sh \
114          /usr/share/mc/bin/mc-wrapper.sh; do
115       if [ -r $wrapper ]; then
116          . $wrapper $MC_SLOW $MC_XTERM "$@"
117          rc=$?
118          MC_FOUND=YES
119          break
120       fi
121    done
122
123    if [ $MC_FOUND = NO ]; then
124       for mc in /usr/local/bin/mc /usr/bin/mc; do
125          if [ -x $mc ]; then
126             MC_TMP_DIR="${TMPDIR-/tmp}/mc-$USER"
127             if [ ! -d MC_TMP_DIR="${TMPDIR-/tmp}/mc-$USER" ]; then
128                MC_TMP_DIR="${TMPDIR-/tmp}"
129             fi
130             MC_PWD_FILE="$MC_TMP_DIR/mc.pwd.$$"
131             mc_type="`mc_type.py $mc`"
132             if [ "$mc_type" = old ]; then
133                $mc -P $MC_SLOW $MC_XTERM "$@" > "$MC_PWD_FILE"
134             elif [ "$mc_type" = new ]; then
135                $mc -P "$MC_PWD_FILE" $MC_SLOW $MC_XTERM "$@"
136             else
137                continue
138             fi
139             rc=$?
140             MC_FOUND=YES
141             cd "`cat \"$MC_PWD_FILE\"`" && /bin/rm "$MC_PWD_FILE"
142             break
143          fi
144       done
145    fi
146
147    if [ $MC_FOUND = NO ]; then
148       echo "Cannot find mc-wrapper.sh or mc" >&2
149       rc=1
150    fi
151
152    [ -n "$MC_SAVE_OPS1" ] && OPS1="$MC_SAVE_OPS1"
153    unset MC_FOUND MC_PWD_FILE MC_SAVE_OPS1 MC_SLOW MC_TMP_DIR MC_XTERM
154
155    return $rc
156 }
157
158
159 mkcd() {
160    if [ $# -ne 1 ]; then
161       echo "Usage: mkcd directory_name" >&2
162    elif [ -d "$1" ]; then
163       cd "$1"
164    elif [ -e "$1" ]; then
165       echo "Error: $1 is a file" >&2
166    else
167       mkdir -p "$1" && cd "$1"
168    fi
169 }
170
171
172 if which tmux >/dev/null 2>&1; then
173    tmux() {
174       case "$TERM" in
175          rxvt)
176             TERM=rxvt-unicode command tmux "$@"
177          ;;
178
179          *)
180             command tmux "$@"
181          ;;
182       esac
183    }
184 fi
185
186
187 if [ "$SHLVL" -eq 1 ] && which startx >/dev/null 2>&1; then
188    X() { startx >> .Xserver.log 2>&1; cyr; rm -f .Xauthority; }
189 fi
190
191 x() { exit; }