]> git.phdru.name Git - dotfiles.git/blob - .shellrc
62da7b79080928d80ddefddea6636d4f8b243fb4
[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"; 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 [ -n "$SLOWTERM" ]; then
80       MC_SLOW="--slow"
81    fi
82
83    case "$TERM" in
84       screen*) # screen, screen.rxvt
85          MC_XTERM="-x"
86       ;;
87    esac
88
89    #TMPDIR="$HOME"/tmp
90    #export TMPDIR
91
92    MC_FOUND=NO
93
94    for wrapper in \
95          /usr/local/share/mc/bin/mc-wrapper.sh \
96          /usr/local/libexec/mc/mc-wrapper.sh \
97          /usr/share/mc/bin/mc-wrapper.sh; do
98       if [ -r $wrapper ]; then
99          . $wrapper $MC_SLOW $MC_XTERM "$@"
100          rc=$?
101          MC_FOUND=YES
102          break
103       fi
104    done
105
106    if [ $MC_FOUND = NO ]; then
107       for mc in /usr/local/bin/mc /usr/bin/mc; do
108          if [ -x $mc ]; then
109             MC_TMP_DIR="${TMPDIR-/tmp}/mc-$USER"
110             if [ ! -d MC_TMP_DIR="${TMPDIR-/tmp}/mc-$USER" ]; then
111                MC_TMP_DIR="${TMPDIR-/tmp}"
112             fi
113             MC_PWD_FILE="$MC_TMP_DIR/mc.pwd.$$"
114             mc_type="`mc_type.py $mc`"
115             if [ "$mc_type" = old ]; then
116                $mc -P $MC_SLOW $MC_XTERM "$@" > "$MC_PWD_FILE"
117             elif [ "$mc_type" = new ]; then
118                $mc -P "$MC_PWD_FILE" $MC_SLOW $MC_XTERM "$@"
119             else
120                continue
121             fi
122             rc=$?
123             MC_FOUND=YES
124             cd "`cat \"$MC_PWD_FILE\"`" && /bin/rm "$MC_PWD_FILE"
125             break
126          fi
127       done
128    fi
129
130    if [ $MC_FOUND = NO ]; then
131       echo "Cannot find mc-wrapper.sh or mc" >&2
132       rc=1
133    fi
134
135    unset MC_FOUND MC_PWD_FILE MC_SLOW MC_TMP_DIR MC_XTERM
136
137    return $rc
138 }
139
140
141 mkcd() {
142    if [ $# -ne 1 ]; then
143       echo "Usage: mkcd directory_name" >&2
144    elif [ -d "$1" ]; then
145       cd "$1"
146    elif [ -e "$1" ]; then
147       echo "Error: $1 is a file" >&2
148    else
149       mkdir -p "$1" && cd "$1"
150    fi
151 }
152
153
154 if which tmux >/dev/null 2>&1; then
155    tmux() {
156       case "$TERM" in
157          rxvt)
158             TERM=rxvt-unicode command tmux "$@"
159          ;;
160
161          *)
162             command tmux "$@"
163          ;;
164       esac
165    }
166 fi
167
168
169 if [ "$SHLVL" -eq 1 ] && which startx >/dev/null 2>&1; then
170    X() { startx >> .Xserver.log 2>&1; cyr; rm -f .Xauthority; }
171 fi
172
173 x() { exit; }