File: hxtools_bashrc.bash

package info (click to toggle)
hxtools 20251011-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,468 kB
  • sloc: ansic: 4,384; perl: 3,467; sh: 1,664; cpp: 353; makefile: 90
file content (160 lines) | stat: -rwxr-xr-x 3,628 bytes parent folder | download | duplicates (2)
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/bin/bash

. /etc/hxloginpref.conf &>/dev/null || :;

if [[ "$HXPREF_ENABLE" == "yes" ]]; then

# --- main big block ---

isroot=0;
if [[ "$UID" -eq 0 ]]; then
	isroot=1;
fi;

hxpref_cd()
{
	local d="$1";
	if [[ -z "$d" ]]; then
		d="$HOME";
		if [[ -z "$d" ]]; then
			command cd;
			return $?;
		fi;
	fi;
	if [[ "$d" == "-" ]]; then
		# The path will be pushed again right away
		popd +1 >/dev/null 2>/dev/null;
	fi;
	pushd "$d" >/dev/null;
	if [[ "$PWD" == "${DIRSTACK[1]}" ]]; then
		popd -0 >/dev/null 2>/dev/null;
	fi;
	if [[ "${#DIRSTACK[@]}" -ge "$HXPREF_DIRSTACK" ]]; then
		popd -0 >/dev/null 2>/dev/null;
	fi;
}

hxpref_popd()
{
	popd >/dev/null || popd +1 >/dev/null 2>/dev/null;
}

hxpref_pushd()
{
	local path;
	if [[ "$#" -eq 0 ]]; then
		pushd .;
	else
		for path in "$@"; do
			pushd "$path";
		done;
	fi;
}

hxpref_beautify_path()
{
	# Show at most the last two path components, if the whole depth of a
	# normalized $PATH is more than 3 levels, e.g.

	#
	#   PATH                                    (NORMALIZED DEPTH LEVEL)
	#
	#   /J/kernel/linux-2.6.17.6                (3)
	#           -> /D/kernel/linux-2.6.17.6     (3)
	#   /J/kernel/linux-2.6.17.6/fs             (4)
	#           -> ../linux-2.6.17.6/fs         (3)
	#   ~/Coding/hxtools                        (3)
	#           -> ~/Coding/hxtools             (3)
	#   ~/Coding/hxtools/bin                    (4)
	#           -> ../hxtools/bin               (3)
	#
	local pw2;
	local wd;
	(
	IFS="/";
	wd="$PWD/"
	# Special treatment for homedir, as ~ is cheaper (shorter) than
	# the full home path ($HOME)
	wd=${wd/#$HOME\//~\/}
	wd=${wd%/};
	set $wd;
	if [ \( -z "$1" -a $# -le "$[$HXPREF_BEAUTIFY_PATH_LEVEL]" \) -o $# -le \
	    "$HXPREF_BEAUTIFY_PATH_LEVEL" ]; then
		echo "$wd";
	else
		eval "echo -en \"../\${$[$#-1]}/\${$#}\"";
	fi;
	);
}

_complete_noop()
{
	return 0;
}

# Use smart directory completion
complete -o nospace -o dirnames -F _complete_noop \
	cd chroot md mkdir pushd rd rmdir;

# Allow truncation via > operator
set +C;

if [[ "$TERM" == "xterm" ]] && [[ -z "$MC_SID" ]]; then
	# Do not use Xterm title inside mc
	PS1_XTERM="\[\e]0;Shell - \h:\w\a\]";
fi;
export PS1_ROOT="$PS1_XTERM\A \h:\$(hxpref_beautify_path) # ";
export PS1_USER="$PS1_XTERM\A \h:\$(hxpref_beautify_path) \$ ";
export PS1_XROOT="$PS1_XTERM\[\e[0;1;30m\]\A \[\e[0;31m\]\h:\$(hxpref_beautify_path) \[\e[1m\]#\[\e[0m\] ";
export PS1_XUSER="$PS1_XTERM\[\e[0;1;30m\]\A \[\e[0;32m\]\h:\$(hxpref_beautify_path) \[\e[0;1;37m\]\$\[\e[0m\] ";
unset PS1_XTERM

eval "$(/usr/bin/dircolors -b /usr/share/hxtools/hxtools_dircolors)";
export QUILT_COLORS="diff_add=32:diff_rem=31:diff_hdr=1;37;44:diff_hunk=35"

# Find out what options this machine's "ls" supports
# Same option finding for "less"
#
LS_OPTIONS="-NT0"
for i in --color=auto --group-dir; do
	/bin/ls "$i" -d >/dev/null 2>&1 && LS_OPTIONS="$LS_OPTIONS $i"
done

export LS_OPTIONS;
# Remove PS1 from export list
unset PS1;

if [[ "$HXPREF_COLORS" == yes ]]; then
	if [[ "$isroot" -eq 1 ]]; then
		PS1="$PS1_XROOT";
	else
		PS1="$PS1_XUSER";
	fi;
else
	unset LS_COLORS;
	if [[ "$isroot" -eq 1 ]]; then
		PS1="$PS1_ROOT";
	else
		PS1="$PS1_USER";
	fi;
fi;

unalias -- + cd.. dir la ll ls-l you 2>/dev/null;
alias -- -="hxpref_popd";
alias ..="cd ../";
alias ...="cd ../../";
alias cd="hxpref_cd";
alias cp="cp -ip";
alias e='$EDITOR';
alias ls='command ls $LS_OPTIONS';
alias l='command ls $LS_OPTIONS -al';
alias md="mkdir -p";
alias mv="mv -i";
alias o="less -S";
alias rd="rmdir";
alias rf="command rm";
alias rm="command rm -i";

# --- end big main block ---

fi; # if [[ "$HXPREF_ENABLE" == "yes" ]];