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