aboutsummaryrefslogtreecommitdiff
path: root/mtr.misc.subr.sh
blob: 268b1c95443a382395c93719e15709b6650db5a6 (plain) (blame)
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
updatevimrc() {
	OLDWD="$(pwd)"
	cd $HOME
	git clone https://git.riedstra.us/mitch/vim-cfg .vim
	if [ $? -gt 0 ] ; then
		cd $HOME/.vim
		git pull origin master
	else
		cd $HOME/.vim
	fi
	./setup.sh && \
	./link-vimrc.sh
	cd $OLDWD
}


# Run Steam 
unfuck_steam() {
LD_PRELOAD='/usr/$LIB/libstdc++.so.6 /usr/$LIB/libgcc_s.so.1 /usr/$LIB/libxcb.so.1 /usr/$LIB/libgpg-error.so' /usr/bin/steam
}
counter_figlet() {
COUNTER="1"; while true ; do figlet "$COUNTER" ; COUNTER="$(echo $COUNTER+1 |bc )" ; sleep 1 ; clear  ; done 
}
counter_single_line() {
COUNTER="1"; while true ; do  sleep 1 ; printf "\t$COUNTER\r" ; COUNTER="$(echo $COUNTER+1 |bc )" ; done 
}

pulltermcolors() {
	file="$HOME/bin/terminal-colors"
	if ! [ -d $HOME/bin ] ; then
		mkdir $HOME/bin
	fi
	pull -u ${UPDATE_URL}/terminal-colors -f $file
	chmod +x $file
}

pkg_switch_branch() {
	_f="/etc/pkg/FreeBSD.conf"
	cp $_f ${_f}.orig
	sed -e's/quarterly/latest/' < ${_f}.orig > ${_f}
}

find_most_recent_python() {
_python="$(which python2 2>/dev/null)"
$_python -c 'import os

max_mtime = 0
for dirname,subdirs,files in os.walk("."):
    for fname in files:
        full_path = os.path.join(dirname, fname)
        mtime = os.stat(full_path).st_mtime
        if mtime > max_mtime:
            max_mtime = mtime
            max_dir = dirname
            max_file = fname

print max_dir, max_file'
}



install_tmx() {
location="/usr/local/bin/tmx"
if ! [ -z $1 ]; then
	location="$1"
fi

TMP=$(mktemp)
pull -u "https://www.rygel.us/etc/tmx.sh" -o "$TMP"
install -m 555 "$TMP" "$location" && echo "Installed to $location"
}

find_most_recent() {
	if [ "$(uname)" != 'linux'] ; then
		path="0"
		while [ $# -gt 0 ] ; do
		case $1 in
			-p)
				path="$2"; shift; shift; ;;
		esac
		done
		if [ $path = "0" ] ; then
			find "$path" -printf "%T@ %Tc %p\n" | sort -n
		else
			echo "You need to specify a path with -p"
		fi
	else
		echo "GNU Find only"
	fi
}

startup_zram() {
	size="512M"

	while [ $# -gt 0 ] ; do
	case $1 in
		-s)
			size="$2"
			shift; shift; ;;
		*)
			echo "Unknown option $1"
			shift; ;;
	esac
	done

	modprobe zram
	zramctl --find --size="$size"
	mkswap -f /dev/zram0
	swapon /dev/zram0

}

time_at_yac() {
  	date --date='September 22 2014'
}
find_php_short_tags() {
	egrep --include="*.php" -rniI '<\?[^px=q]' . --color=force
}
gentags() {
	options="-R --links --languages=php,-javascript"
	dir="."
	while [ $# -gt 0 ] ; do
		case $1 in
		-o)
			options="$2"
			shift; shift;
		;;
		esac
	done

	if [ -x $(which exctags 2>/dev/null) ] ; then
		$(which exctags 2>/dev/null) $options $dir
	elif [ -x $(which ctags 2>/dev/null) ] ; then
		$(which ctags 2>/dev/null) $options $dir
	fi
}
set_tmux_title() {
	text=""
	while [ $# -gt 0 ] ; do
	   text="$( echo $text $1)";
	   shift;
	done
	printf $'\033k'"${text}"$'\033\\';
}
set_title() {
	text=""
	while [ $# -gt 0 ] ; do
	   text="$( echo $text $1)";
	   shift;
	done
	printf $'\033]0;'"$text"$'\007';
}

set_ps1() {
		PS1='$(precmd)${BG}${ACCENT_C}${ACCENT_P}${USER_C}${USER:=$(id -un)}@$(hostname)${ACCENT_C}${ACCENT_P} ${ACCENT_P}${PATH_C}${PWD:-?}${ACCENT_C}${ACCENT_P}${END_C}
${END_P} '
		export PS1;
}
set_root_ps1() {
PS1='$(precmd)${BG}${ACCENT_C}${ACCENT_P}${HOST_C}$(hostname)${ACCENT_C}${ACCENT_P} ${ACCENT_P}${PATH_C}${PWD:-?}${ACCENT_C}${ACCENT_P}${END_C}
${END_P} '
export PS1;
}

# RED: 31, GREEN: 32, YELLOW: 33, BLUE: 34, MAGENTA: 35, CYAN: 36, WHITE: 37, GREY 38. and No color which is 0.
set_prompt() {
	if [ `id -u` -eq 0 ] ; then
		# Previously
		# Red for root, and no username 
		# PS1="$(hostname) \$PWD
		echo $TERM | grep "256color$" > /dev/null 2>&1
		if [ $? -eq 0 ] ; then
			BG=""
			ACCENT_C=""
			ACCENT_P="|"
			HOST_C=""
			PATH_C=""
			END_C=""
			set_root_ps1
			END_P="#"
		else
			BG=""
			ACCENT_C=""
			ACCENT_P="|"
			HOST_C=""
			PATH_C=""
			END_P="#"
		fi
		set_root_ps1
	else	
		# Previously
		# PS1="${USER:=$(id -un)}@$(hostname) \$PWD
		echo $TERM | grep "256color$" > /dev/null 2>&1
		if [ $? -eq 0 ] ; then
			BG=""
			ACCENT_C=""
			ACCENT_P="|"
			USER_C=""
			PATH_C=""
			END_C=""
			END_P="≈"
		else
			BG=""
			ACCENT_C=""
			ACCENT_P="|"
			USER_C=""
			PATH_C=""
			END_C=""
			END_P="$"
		fi
		set_ps1
	fi
}