aboutsummaryrefslogtreecommitdiff
path: root/mkshrc
blob: 9bd9d5784cff51729ca190d4720d897c0970f44a (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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
## Mitch's General shell configuration
## MIT LICENSE
# vim: syn=sh

# How to install:
# For Bash:
# curl https://www.rygel.us/etc/mkshrc > $HOME/.mkshrc && echo '. $HOME/.mkshrc' >> .bashrc
#
# Personally I use this with mksh, .mkshrc is auto loaded by mksh

# This will hopefully fix the bullshit with zsh
if \
	[ $SHELL = "/bin/zsh" ] || \
	[ $SHELL = "/usr/bin/zsh" ] || \
	[ $SHELL = "/usr/local/bin/zsh" ] ; then
# Bash doesn't like an empty if statement apparently
printf ""
else


#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#  ____                            _   
# |  _ \ _ __ ___  _ __ ___  _ __ | |_ 
# | |_) | '__/ _ \| '_ ` _ \| '_ \| __|
# |  __/| | | (_) | | | | | | |_) | |_ 
# |_|   |_|  \___/|_| |_| |_| .__/ \__|
#                           |_|        
#  _____                 _   _                 
# |  ___|   _ _ __   ___| |_(_) ___  _ __  ___ 
# | |_ | | | | '_ \ / __| __| |/ _ \| '_ \/ __|
# |  _|| |_| | | | | (__| |_| | (_) | | | \__ \
# |_|   \__,_|_| |_|\___|\__|_|\___/|_| |_|___/
#                                              
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
precmd() {
	typeset e=$?

	(( e )) && print -n "$e|"
}
set_ps1() {
		PS1='$(precmd)${BG}${ACCENT_C}${ACCENT_P}${USER_C}${USER:=$(id -un)}@$(hostname -s)${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 -s)${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 -s) \$PWD
		BG=""
		ACCENT_C=""
		ACCENT_P="|"
		HOST_C=""
		PATH_C=""
		END_C=""
		END_P="#"
		set_root_ps1
	else	
		# Previously
		# PS1="${USER:=$(id -un)}@$(hostname -s) \$PWD
		BG=""
		ACCENT_C=""
		ACCENT_P="|"
		USER_C=""
		PATH_C=""
		END_C=""
		END_P="$"
		set_ps1
	fi
}
set_basic_prompt() {
	PS1="$(precmd)${USER:=$(id -un)}@$(hostname -s) \$PWD $ "
	export PS1;
}
set_super_basic_prompt() {
	alias cd=do_cd
}
do_cd() {
        builtin cd $@
        pwd=${PWD##HOME}
        [ ${#pwd} -lt ${#PWD} ] && pwd="~$pwd"
        [ "$hostname" ] || hostname=$(hostname)
        PS1="$USER@$hostname:$pwd \$ "
        [ $(id -u) -eq 0 ] && PS1="$USER@$hostname:$pwd # "
}

# ZSH doesn't handle these functions all too well
fi

#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#     _    _ _             _____                 _   _                 
#    / \  | (_) __ _ ___  |  ___|   _ _ __   ___| |_(_) ___  _ __  ___ 
#   / _ \ | | |/ _` / __| | |_ | | | | '_ \ / __| __| |/ _ \| '_ \/ __|
#  / ___ \| | | (_| \__ \ |  _|| |_| | | | | (__| |_| | (_) | | | \__ \
# /_/   \_\_|_|\__,_|___/ |_|   \__,_|_| |_|\___|\__|_|\___/|_| |_|___/
#                                                                      
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
setaliases() {
	alias ls="ls -F";
	alias l="ls -lh";
	alias ll="ls -l";
	alias g="grep";
	alias m="$PAGER";
	alias j="jobs";
	alias p="pwd";
	alias gdb='gdb -q'
	alias bc='bc -q'
	alias egrep='egrep --color=auto'
	alias eg='egrep'
	alias egf='egrep --color=force'
	alias search='egrep -rniI'
}

setcoloraliases() {
	if [ `uname` = "Linux" ] ; then
		alias ls="ls --color=auto -F";
		alias lm='ls -lh --color=force | more';
	elif [ `uname` = "FreeBSD" ] ; then
		alias ls="ls -FG";
		alias lm='CLICOLOR_FORCE="1" ls -l | less -r';
	fi

	alias grep="grep --color=auto";
	alias diff='colordiff';
	alias search='egrep --color=auto -rnI';
	alias t='tree -CdL'
}

setsudoaliases() {
	if which sudo > /dev/null 2>&1 && [ -x "$(which sudo)" ] ; then
	# Package managers
	alias apt-get='sudo apt-get'
	alias yum='sudo dnf'
	alias dnf='sudo dnf'
	alias pacman='sudo pacman'
	alias pkg='sudo pkg'

	# Filesystem utilities
	alias zfs='sudo zfs'
	alias btrfs='sudo btrfs'
	alias mount='sudo mount'
	fi
}

# Usage debugstarttls $ipaddr:$port
debugstarttls() {
	openssl s_client -starttls smtp -crlf -connect $1 $2
}


#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#  __  __ _            _____                 _   _                 
# |  \/  (_)___  ___  |  ___|   _ _ __   ___| |_(_) ___  _ __  ___ 
# | |\/| | / __|/ __| | |_ | | | | '_ \ / __| __| |/ _ \| '_ \/ __|
# | |  | | \__ \ (__  |  _|| |_| | | | | (__| |_| | (_) | | | \__ \
# |_|  |_|_|___/\___| |_|   \__,_|_| |_|\___|\__|_|\___/|_| |_|___/
#                                                                  
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# 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
}
# First argument is the interface on which to scan
ipv6_local_hosts() {
if ! [ -z $1 ] ; then
	interface="$1"
	ping6 -c 3 ff02::2%$interface \
		| grep 'bytes from' \
		| awk '{print $4}' \
		| sort \
		| uniq \
		| sed -e's/:$//'
else
	echo "You need to specify an interface"
fi
}
set_nocaps() {
	setxkbmap -option ctrl:nocaps
	setxkbmap -option shift:breaks_caps
}
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
echo '#!/bin/sh

# Modified further by Mitchell Riedstra to be compatible with
# /bin/sh

#
# Modified TMUX start script from:
#     http://forums.gentoo.org/viewtopic-t-836006-start-0.html
#
# Store it to `~/bin/tmx` and issue `chmod +x`.
#

# Works because bash automatically trims by assigning to variables and by 
# passing arguments
trim() { echo $1; }

if [ -z "$1" ]; then
    echo "Specify session name as the first argument"
    exit
fi

# Only because I often issue `ls` to this script by accident
if [ "$1" == "ls" ]; then
    tmux ls
    exit
fi

base_session="$1"
# This actually works without the trim() on all systems except OSX
tmux_nb=$(trim `tmux ls | grep "^$base_session" | wc -l`)
if [ "$tmux_nb" == "0" ]; then
    echo "Launching tmux base session $base_session ..."
    tmux new-session -s $base_session
else
    # Make sure we are not already in a tmux session
    if [ -z "$TMUX" ]; then
        # Kill defunct sessions first
        old_sessions=$(tmux ls 2>/dev/null | egrep "^[0-9]{14}.*[0-9]+\)$" | cut -f 1 -d:)
        for old_session_id in $old_sessions; do
            tmux kill-session -t $old_session_id
        done

        echo "Launching copy of base session $base_session ..."
        # Session is is date and time to prevent conflict
        session_id=`date +%Y%m%d%H%M%S`
        # Create a new session (without attaching it) and link to base session 
        # to share windows
        tmux new-session -d -t $base_session -s $session_id
        # Create a new window in that session
        #tmux new-window
        # Attach to the new session
        tmux attach-session -t $session_id
        # When we detach from it, kill the session
        tmux kill-session -t $session_id
    fi
fi
' > $location && chmod +x $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

}
# Sometimes useful function for unmounting a chroot dir on Linux
umount_recursive() {
	case $1 in
		-h|--help|"")
			cat <<-EOF
				Specifiy the full path to the mountpoint
				and this function will do it's best to
				unmount all child filesystems and the path
				specified
				Example:
					$0 /path/to/filesystem/with/lots/of/mountpoints
				Options:
					-f|--force
			EOF
		;;
		-f|--force)
			local _path="$2"
			local filesystems=`cat /proc/mounts | grep $_path | awk '{print $2}' | sort -r` 
			for filesystem in $filesystems ; do
				umount -f $filesystem
			done
		;;
		*)
			local _path="$1"
			local filesystems=`cat /proc/mounts | grep $_path | awk '{print $2}' | sort -r` 
			for filesystem in $filesystems ; do
				umount $filesystem
			done
		;;
	esac
}
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';
}

# Usage: dir_oct:file_oct path
setperms() {
	 dir_perms=$(echo $1 | awk -F: '{print $1}')
	file_perms=$(echo $1 | awk -F: '{print $2}')
	find $2 -type f -exec chmod $file_perms {} \; ;
	find $2 -type d -exec chmod $dir_perms  {} \; ;
}

timestamp() {
	date +%m.%d.%y_%H.%M.%S
}


#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#   ____             __ _                       _   _             
#  / ___|___  _ __  / _(_) __ _ _   _ _ __ __ _| |_(_) ___  _ __  
# | |   / _ \| '_ \| |_| |/ _` | | | | '__/ _` | __| |/ _ \| '_ \ 
# | |__| (_) | | | |  _| | (_| | |_| | | | (_| | |_| | (_) | | | |
#  \____\___/|_| |_|_| |_|\__, |\__,_|_|  \__,_|\__|_|\___/|_| |_|
#                         |___/                                   
#  __  __                                                   _   
# |  \/  | __ _ _ __   __ _  __ _  ___ _ __ ___   ___ _ __ | |_ 
# | |\/| |/ _` | '_ \ / _` |/ _` |/ _ \ '_ ` _ \ / _ \ '_ \| __|
# | |  | | (_| | | | | (_| | (_| |  __/ | | | | |  __/ | | | |_ 
# |_|  |_|\__,_|_| |_|\__,_|\__, |\___|_| |_| |_|\___|_| |_|\__|
#                           |___/                               
#  _____                 _   _                 
# |  ___|   _ _ __   ___| |_(_) ___  _ __  ___ 
# | |_ | | | | '_ \ / __| __| |/ _ \| '_ \/ __|
# |  _|| |_| | | | | (__| |_| | (_) | | | \__ \
# |_|   \__,_|_| |_|\___|\__|_|\___/|_| |_|___/
#                                              
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

pull() {
	url=""
	file=""
	while [ $# -gt 0 ] ; do
		case $1 in
			-f)
				file="$2"
				shift; shift; ;;
			-u)
				url="$2"
				shift; shift; ;;
		esac
	done
	if [ -x $(which curl 2>/dev/null) ] ; then
		$(which curl 2>/dev/null) $url > $file
	elif [ -x $(which wget 2>/dev/null) ] ; then
		$(which wget 2>/dev/null) $url -O $file
	elif [ -x $(which fetch 2>/dev/null) ] ; then
		$(which fetch 2>/dev/null) $url -o $file
	fi
}
pulldotfile() {
	file="$1"
	pull -u "${UPDATE_URL}${file}" -f "$HOME/.${file}"
}
pullkeys() {
	file="keys/$1"
	if ! [ -d $HOME/.ssh ] ; then mkdir $HOME/.ssh ; fi
	chmod 700 $HOME/.ssh
	chmod 600 $HOME/.ssh/authorized_keys
	mv "$HOME/.ssh/authorized_keys" "$HOME/.ssh/authorized_keys.$(timestamp)"
	pull -u "${UPDATE_URL}${file}" -f "$HOME/.ssh/authorized_keys"
	chmod 600 $HOME/.ssh/authorized_keys
}
pullsshconfig() {
	file="ssh/config"
	pull -u "${UPDATE_URL}${file}" -f "$HOME/.ssh/config"
}
updatetmuxconf() {
	pulldotfile "tmux.conf"
	if ! [ -e $HOME/.tmux.conf.local ] ; then
		touch $HOME/.tmux.conf.local
	fi
}
updategitconf() {
	pulldotfile "gitconfig"
}
updateshell() {
	pulldotfile "mkshrc"
	. $HOME/.mkshrc
}
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
}


#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#  __  __ _             ____      _            
# |  \/  (_)___  ___   / ___|___ | | ___  _ __ 
# | |\/| | / __|/ __| | |   / _ \| |/ _ \| '__|
# | |  | | \__ \ (__  | |__| (_) | | (_) | |   
# |_|  |_|_|___/\___|  \____\___/|_|\___/|_|   
#                                              
#  _____                 _   _                 
# |  ___|   _ _ __   ___| |_(_) ___  _ __  ___ 
# | |_ | | | | '_ \ / __| __| |/ _ \| '_ \/ __|
# |  _|| |_| | | | | (__| |_| | (_) | | | \__ \
# |_|   \__,_|_| |_|\___|\__|_|\___/|_| |_|___/
#                                              
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

setcolorterminal() {
	case $TERM in
	xterm*)
		export TERM=xterm-256color
		set_title $(hostname)
		# printf $'\033]0;'"$(hostname)"$'\007';
	;;
	screen*)
		export TERM=screen-256color
		set_tmux_title $(whoami)
		# printf $'\033k'"$(whoami)"$'\033\\';
	;;
	esac
}

setlscolors() {
	if [ "$(uname)" = "Linux" ] ; then
		export LS_COLORS='di=36;40:ln=1;31;40:so=32;40:pi=33;40:ex=1;32;40:bd=34;46:cd=34;43:su=0;41:sg=0;46:tw=0;42:ow=0;43:'
	elif [ "$(uname)" = "FreeBSD" ] ; then
		export LSCOLORS='gxBxcxdxCxegedabagacad'
	fi
}

colormanpages() {
	export LESS_TERMCAP_mb=""
	export LESS_TERMCAP_md=""
	export LESS_TERMCAP_me=""
	export LESS_TERMCAP_se=""
	export LESS_TERMCAP_so=""
	export LESS_TERMCAP_ue=""
	export LESS_TERMCAP_us=""

	## Gentoo is nuts
	export GROFF_NO_SGR=1
}

#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# __  __ _            _____                 _   _                 
#|  \/  (_)___  ___  |  ___|   _ _ __   ___| |_(_) ___  _ __  ___ 
#| |\/| | / __|/ __| | |_ | | | | '_ \ / __| __| |/ _ \| '_ \/ __|
#| |  | | \__ \ (__  |  _|| |_| | | | | (__| |_| | (_) | | | \__ \
#|_|  |_|_|___/\___| |_|   \__,_|_| |_|\___|\__|_|\___/|_| |_|___/
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
set_editor() {
	export EDITOR="vi"

	if [ -x "$(which nvim)" ] ; then
		export EDITOR="$(which nvim)"
	elif [ -x "$(which vim)" ] ; then
		export EDITOR="$(which vim)"
	fi

	# Set an alias for our editor of choice
	alias vi="$EDITOR"
	alias edit="$EDITOR"
	alias e="$EDITOR"
}
set_pager() {
	if [ -x "$(which less)" ] ; then
		export EDITOR="$(which less)"
	elif [ -x "$(which more)" ] ; then
		export EDITOR="$(which more)"
	fi
}
set_lang() {
export CHARSET="$1";
export LANG="$1";
}
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#  ____  _          _ _ 
# / ___|| |__   ___| | |
# \___ \| '_ \ / _ \ | |
#  ___) | | | |  __/ | |
# |____/|_| |_|\___|_|_|
#                       
#   ____             __ _                       _   _             
#  / ___|___  _ __  / _(_) __ _ _   _ _ __ __ _| |_(_) ___  _ __  
# | |   / _ \| '_ \| |_| |/ _` | | | | '__/ _` | __| |/ _ \| '_ \ 
# | |__| (_) | | | |  _| | (_| | |_| | | | (_| | |_| | (_) | | | |
#  \____\___/|_| |_|_| |_|\__, |\__,_|_|  \__,_|\__|_|\___/|_| |_|
#                         |___/                                   
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

NEWLINE='$(printf "\n")'
SHELL_CONFIG=".mkshrc"
PRELOAD="$HOME/${SHELL_CONFIG}.pre"
LOCAL="$HOME/${SHELL_CONFIG}.local"
UPDATE_URL="https://www.rygel.us/etc/"
BASH_ROOT_SHELL_COLOR=""
BASH_SHELL_COLOR=""
FANCY_PROMPT=1
COLOR=1

# For use with SSL functions
# Just use easy-rsa, it's less hassle

# Do not load our system profile
# . /etc/profile


############################################################
########## Enviroment variables
set_pager
set_editor
export PATH="$HOME/bin:$PATH"
export VISUAL="$EDITOR"
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin

set_lang "en_US.UTF-8"

# Load pre config
if [ -e $PRELOAD ] ; then
	. $PRELOAD
fi


if
	[ $SHELL = "/bin/ksh" ] ||
	[ $SHELL = "/bin/mksh" ] ||
	[ $SHELL = "/usr/bin/mksh" ] ||
	[ $SHELL = "/usr/local/bin/mksh" ]
then
	export HISTFILE="$HOME/.ksh_history"
	set -o emacs
	bind ^L=clear-screen

	setaliases
	setsudoaliases
	
	if [ $COLOR -eq 1 ] ; then
		set_prompt
		colormanpages
		setcolorterminal
		setcoloraliases
		setlscolors
	fi
elif	[ $SHELL = "/bin/zsh" ] ||
		[ $SHELL = "/usr/bin/zsh" ] ||
		[ $SHELL = "/usr/local/bin/zsh" ] ; then
	set -o emacs

	setaliases
	setsudoaliases

	if [ $COLOR -eq 1 ] ; then
		colormanpages
		setcolorterminal
		setcoloraliases
		setlscolors
	fi
else
	# Support other shells
	setaliases
	setsudoaliases

	[ $SHELL = "/bin/sh" ] && set_super_basic_prompt

	# Set a prompt for bash
	if [ $SHELL = "/usr/local/bin/bash" ] || \
	   [ $SHELL = "/usr/bin/bash" ] || \
	   [ $SHELL = "/bin/bash" ] ; then

		NOCOLOR=$'\033[0m'
		
		if [ `id -u` -eq 0 ] ; then
			export PS1=$BASH_ROOT_SHELL_COLOR"[\u@\h \w]\$ "$NOCOLOR
		else
			export PS1=$BASH_SHELL_COLOR"[\u@\h \w]\$ "$NOCOLOR
		fi
	fi

	if [ $COLOR -eq 1 ] ; then
		colormanpages
		setcolorterminal
		setcoloraliases
		setlscolors
	fi
fi

# Include local configuration options
if [ -f $LOCAL ] ; then
	. $LOCAL
fi