small fix and additions
[distro-setup] / brc
1 #!/bin/bash
2 # this gets sourced. shebang is just for file mode detection
3
4 # note, to catch errors in functions but not outside, do:
5 # set -E -o pipefail
6 # trap return ERR
7 # trap 'trap ERR' RETURN
8
9
10
11 ############
12 # settings #
13 ############
14
15 CDPATH=.
16
17 set -o pipefail
18
19 # remove all aliases. aliases provided by the system tend to get in the way,
20 # for example, error happens if I try to define a function the same name as an alias
21 unalias -a
22
23 # remove gnome keyring warning messages
24 # there is probably a more proper way, but I didn't find any easily on google
25 # now using xfce+xmonad instead of vanilla xmonad, so disabling this
26 #unset GNOME_KEYRING_CONTROL
27
28 # use extra globing features.
29 shopt -s extglob
30 # include .files when globbing, but ignore files name . and ..
31 # setting this also sets dotglob.
32 # Note, this doesn't work in bash 4.4 anymore, for paths with
33 # more than 1 directory, like a/b/.foo, since * is fixed to not match /
34 export GLOBIGNORE=*/.:*/..
35
36 # broken with bash_completion package. Saw a bug for this once. Don't anymore.
37 # still broken in wheezy
38 # still buggered in latest stable from the web, version 2.1
39 # perhaps its fixed in newer git version, which fails to make for me
40 # this note is from 6-2014.
41 # Also, enabling this before sourcing .bashrc makes PATH be empty.
42 #shopt -s nullglob
43
44 # make tab on an empty line do nothing
45 shopt -s no_empty_cmd_completion
46
47 # advanced completion
48 # http://bash-completion.alioth.debian.org/
49 # might be sourced by the system already, but I've noticed it not being sourced before
50 if ! type _init_completion &> /dev/null && [[ -r "/usr/share/bash-completion/bash_completion" ]]; then
51 . /usr/share/bash-completion/bash_completion
52 fi
53
54
55 # fix spelling errors for cd, only in interactive shell
56 shopt -s cdspell
57 # append history instead of overwritting it
58 shopt -s histappend
59 # for compatibility, per gentoo/debian bashrc
60 shopt -s checkwinsize
61 # attempt to save multiline single commands as single history entries.
62 shopt -s cmdhist
63 # enable **
64 shopt -s globstar
65
66
67 # inside emcas fixes
68 if [[ $RLC_INSIDE_EMACS ]]; then
69 # EMACS is used by bash on startup, but we don't need it anymore.
70 # plus I hit a bug in a makefile which inherited it
71 unset EMACS
72 export RLC_INSIDE_EMACS
73 export PAGER=cat
74 export MANPAGER=cat
75 # scp completion does not work, but this doesn't fix it. todo, figure this out
76 complete -r scp &> /dev/null
77 # todo, remote file completion fails, figure out how to turn it off
78 export NODE_DISABLE_COLORS=1
79 # This get's rid of ugly terminal escape chars in node repl
80 # sometime, I'd like to have completion working in emacs shell for node
81 # the offending chars can be found in lib/readline.js,
82 # things that do like:
83 # stream.write('\x1b[' + (x + 1) + 'G');
84 # We can remove them and keep readline, for example by doing this
85 # to start a repl:
86 #!/usr/bin/env nodejs
87 # var readline = require('readline');
88 # readline.cursorTo = function(a,b,c) {};
89 # readline.clearScreenDown = function(a) {};
90 # const repl = require('repl');
91 # var replServer = repl.start('');
92 #
93 # no prompt, or else readline complete seems to be confused, based
94 # on our column being different? node probably needs to send
95 # different kind of escape sequence that is not ugly. Anyways,
96 # completion doesn't work yet even with the ugly prompt, so whatever
97 #
98 export NODE_NO_READLINE=1
99
100 fi
101
102
103 if [[ $- == *i* ]]; then
104 # for readline-complete.el
105 if [[ $RLC_INSIDE_EMACS ]]; then
106 # all for readline-complete.el
107 stty echo
108 bind 'set horizontal-scroll-mode on'
109 bind 'set print-completions-horizontally on'
110 bind '"\C-i": self-insert'
111 else
112 # arrow keys. for other terminals, see http://unix.stackexchange.com/questions/10806/how-to-change-previous-next-word-shortcut-in-bash
113 if [[ $TERM == "xterm" ]]; then
114 bind '"\e[1;5C": shell-forward-word' 2>/dev/null
115 bind '"\e[1;5D": shell-backward-word' 2>/dev/null
116 else
117 bind '"\eOc": shell-forward-word'
118 bind '"\eOd": shell-backward-word'
119 fi
120 # terminal keys: C-c, C-z. the rest defined by stty -a are, at least in
121 # gnome-terminal, overridden by bash, or disabled by the system
122 stty werase undef lnext undef stop undef start undef
123
124 fi
125
126 fi
127
128
129 # history number. History expansion is good.
130 PS4='$LINENO+ '
131 # history file size limit, set to unlimited.
132 # this needs to be different from the default because
133 # default HISTFILESIZE is 500 and could clobber our history
134 HISTFILESIZE=
135 # max commands 1 session can append/read from history
136 HISTSIZE=100000
137 # my own history size limit based on lines
138 HISTFILELINES=1000000
139 HISTFILE=$HOME/.bh
140 # the time format display when doing the history command
141 # also, setting this makes the history file record time
142 # of each command as seconds from the epoch
143 HISTTIMEFORMAT="%I:%M %p %m/%d "
144 # consecutive duplicate lines don't go in history
145 HISTCONTROL=ignoredups
146 # works in addition to HISTCONTROL to do more flexible things
147 # it could also do the same things as HISTCONTROL and thus replace it,
148 # but meh. dunno why, but just " *" does glob expansion, so use [ ] to avoid it.
149 HISTIGNORE='k *:[ ]*'
150
151 export BC_LINE_LENGTH=0
152
153
154 # note, if I use a machine I don't want files readable by all users, set
155 # umask 077 # If fewer than 4 digits are entered, leading zeros are assumed
156
157 C_DEFAULT_DIR=/a
158
159
160 ###################
161 ## include files ###
162 ###################
163 for _x in /a/bin/distro-functions/src/* /a/bin/!(githtml)/*-function?(s); do
164 source "$_x"
165 done
166 unset _x
167 # so I can share my bashrc
168 for x in /a/bin/bash_unpublished/source-!(.#*); do source $x; done
169 source $(dirname $(readlink -f $BASH_SOURCE))/path_add-function
170 source /a/bin/log-quiet/logq-function
171 path_add /a/exe
172 path_add --ifexists --end /a/opt/adt-bundle*/tools /a/opt/adt-bundle*/platform-tools
173 # based on readme.debian. dunno if this will break on other distros.
174 _x=/usr/share/wcd/wcd-include.sh
175 if [[ -e $_x ]]; then source $_x; fi
176
177
178 ###############
179 ### aliases ###
180 ###############
181
182 # very few aliases, functions are always preferred.
183
184 # ancient stuff.
185 if [[ $OS == Windows_NT ]]; then
186 alias ffs='cygstart "/c/Program Files (x86)/Mozilla Firefox/firefox.exe" -P scratch'
187 export DISPLAY=nt
188 alias j='command cygpath'
189 alias t='command cygstart'
190 alias cygstart='echo be quick, use the alias "t" instead :\)'
191 alias cygpath='echo be quick, use the alias "j" instead :\)'
192 fi
193
194
195
196 # keep this in mind? good for safety.
197 # alias cp='cp -i'
198 # alias mv='mv -i'
199
200
201 # remove any default aliases for these
202 unalias ls ll grep &>/dev/null ||:
203
204
205
206
207
208
209
210
211
212 #####################
213 ### functions ####
214 #####################
215
216
217 ..() { c ..; }
218 ...() { c ../..; }
219 ....() { c ../../..; }
220 .....() { c ../../../..; }
221 ......() { c ../../../../..; }
222
223
224 # file cut copy and paste, like the text buffers :)
225 # I havn't tested these.
226 _fbufferinit() { # internal use by
227 ! [[ $my_f_tempdir ]] && my_f_tempdir=$(mktemp -d)
228 rm -rf "$my_f_tempdir"/*
229 }
230 fcp() { # file cp
231 _fbufferinit
232 cp "$@" "$my_f_tempdir"/
233 }
234 fct() { # file cut
235 _fbufferinit
236 mv "$@" "$my_f_tempdir"/
237 }
238 fpst() { # file paste
239 [[ $2 ]] && { echo too many arguments; return 1; }
240 target=${1:-.}
241 cp "$my_f_tempdir"/* "$target"
242 }
243
244
245 # todo, update this
246 complete -F _longopt la lower low rlt rld rl lld ts ll dircp ex fcp fct fpst gr
247
248
249 _cdiff-prep() {
250 # join options which are continued to multiples lines onto one line
251 local first=true
252 grep -vE '^([ \t]*#|^[ \t]*$)' "$1" | while IFS= read -r line; do
253 # remove leading spaces/tabs. assumes extglob
254 if [[ $line == "[ ]*" ]]; then
255 line="${line##+( )}"
256 fi
257 if $first; then
258 pastline="$line"
259 first=false
260 elif [[ $line == *=* ]]; then
261 echo "$pastline" >> "$2"
262 pastline="$line"
263 else
264 pastline="$pastline $line"
265 fi
266 done
267 echo "$pastline" >> "$2"
268 }
269
270 _khfix_common() {
271 local h=${1##*@}
272 ssh-keygen -R $h -f $(readlink -f ~/.ssh/known_hosts)
273 local x=$(timeout 0.1 ssh -v $1 |& sed -rn "s/debug1: Connecting to $h \[([^\]*)].*/\1/p");
274 ssh-keygen -R $x -f $(readlink -f ~/.ssh/known_hosts)
275 }
276 khfix() { # known hosts fix
277 _khfix_common "$@"
278 ssh $1 :
279 }
280 khcopy() {
281 _khfix_common "$@"
282 ssh-copy-id $1
283 }
284
285 a() {
286 beet "${@}"
287 }
288
289 ack() { ack-grep "$@"; }
290
291 astudio() {
292 # googling android emulator libGL error: failed to load driver: r600
293 # lead to http://stackoverflow.com/a/36625175/14456
294 export ANDROID_EMULATOR_USE_SYSTEM_LIBS=1
295 /a/opt/android-studio/bin/studio.sh "$@" &r;
296 }
297
298 b() {
299 # backwards
300 c -
301 }
302
303 bashrcpush () {
304 local startdir="$PWD"
305 cd ~
306 for x in "$@"; do
307 ssh $x mkdir -p bin/distro-functions/src
308 tar cz bin/semi-private bin/distro-functions/src | ssh $x tar xz
309 done
310 cd $(mktemp -d)
311 command cp /a/c/repos/bash/!(.git|..|.) ~/.gitconfig .
312 for x in "$@"; do
313 tar cz * | ssh $x tar xz
314 done
315 cd "$startdir"
316 }
317
318 bkrun() {
319 # use -p from interactive shell
320 btrbk-run -p "$@"
321 }
322
323 bfg() { java -jar /a/opt/bfg-1.12.14.jar "$@"; }
324
325 btc() {
326 local f=/etc/bitcoin/bitcoin.conf
327 bitcoin-cli -$(s grep rpcuser= $f) -$(s grep rpcpassword= $f) "$@"
328 }
329
330 btcusd() {
331 local price
332 price="$(curl -s https://blockchain.info/ticker | jq .USD.last)"
333 printf "$%s\n" "$price"
334 if [[ $1 ]]; then
335 printf "$%.2f\n" "$(echo "scale=2; $price * $1"| bc -l)"
336 fi
337 }
338
339 # c. better cd
340 if [[ $RLC_INSIDE_EMACS ]]; then
341 c() { wcd -c -z 50 -o "$@"; }
342 else
343 # lets see what the fancy terminal does from time to time
344 c() { wcd -c -z 50 "$@"; }
345 fi
346
347 caa() { git commit --amend --no-edit -a; }
348
349 calc() { echo "scale=3; $*" | bc -l; }
350 # no having to type quotes, but also no command history:
351 clc() {
352 local x
353 read -r x
354 echo "scale=3; $x" | bc -l
355 }
356
357 cam() {
358 git commit -am "$*"
359 }
360
361 ccat () { # config cat. see a config without extra lines.
362 grep '^\s*[^[:space:]#]' "$@"
363 }
364
365 cdiff() {
366 # diff config files,
367 # setup for format of postfix, eg:
368 # option = stuff[,]
369 # [more stuff]
370 local pastline
371 local unified="$(mktemp)"
372 local f1="$(mktemp)"
373 local f2="$(mktemp)"
374 _cdiff-prep "$1" "$f1"
375 _cdiff-prep "$2" "$f2"
376 cat "$f1" "$f2" | grep -Po '^[^=]+=' | sort | uniq > "$unified"
377 while IFS= read -r line; do
378 # the default bright red / blue doesn't work in emacs shell
379 dwdiff -cblue,red -A best -d " ," <(grep "^$line" "$f1" || echo ) <(grep "^$line" "$f2" || echo ) | colordiff
380 done < "$unified"
381 }
382
383 cgpl()
384 {
385 if (($#)); then
386 cp /a/bin/data/COPYING "$@"
387 else
388 cp /a/bin/data/COPYING .
389 fi
390 }
391 capache()
392 {
393 if (($#)); then
394 cp /a/bin/data/LICENSE "$@"
395 else
396 cp /a/bin/data/LICENSE .
397 fi
398 }
399 chown() {
400 # makes it so chown -R symlink affects the symlink and its target.
401 if [[ $1 == -R ]]; then
402 shift
403 command chown -h "$@"
404 command chown -R "$@"
405 else
406 command chown "$@"
407 fi
408 }
409
410 cim() {
411 git commit -m "$*"
412 }
413
414 cl() {
415 # choose recent directory. cl = cd list
416 c =
417 }
418
419 d() { builtin bg; }
420 complete -A stopped -P '"%' -S '"' d
421
422 dat() { # do all tee, for more complex scripts
423 tee >(ssh frodo bash -l) >(bash -l) >(ssh x2 bash -l) >(ssh tp bash -l)
424 }
425 da() { # do all
426 local host
427 "$@"
428 for host in x2 tp treetowl; do
429 ssh $host "$@"
430 done
431 }
432
433 dc() {
434 diff --strip-trailing-cr -w "$@" # diff content
435 }
436
437 debian_pick_mirror () {
438 # netselect-apt finds a fast mirror.
439 # but we need to replace the mirrors ourselves,
440 # because it doesn't do that. best it can do is
441 # output a basic sources file
442 # here we get the server it found, get the main server we use
443 # then substitute all instances of one for the other in the sources file
444 # and backup original to /etc/apt/sources.list-original.
445 # this is idempotent. the only way to identify debian sources is to
446 # note the original server, so we put it in a comment so we can
447 # identify it later.
448 local file=$(mktemp -d)/f # safe way to get file name without creating one
449 sudo netselect-apt -o "$file" || return 1
450 url=$(grep ^\\w $file | head -n1 | awk '{print $2}')
451 sudo cp -f /etc/apt/sources.list /etc/apt/sources.list-original
452 sudo sed -ri "/http.us.debian.org/ s@( *[^ #]+ +)[^ ]+([^#]+).*@\1$url\2# http.us.debian.org@" /etc/apt/sources.list
453 sudo apt-get update
454 }
455
456 despace() {
457 local x y
458 for x in "$@"; do
459 y="${x// /_}"
460 safe_rename "$x" "$y"
461 done
462 }
463
464 dt() {
465 date "+%A, %B %d, %r" "$@"
466 }
467
468 dus() {
469 du -sh ${@:-*} | sort -h
470 }
471
472
473
474 e() { echo "$@"; }
475
476
477 ediff() {
478 [[ ${#@} == 2 ]] || { echo "error: ediff requires 2 arguments"; return 1; }
479 emacs --eval "(ediff-files \"$1\" \"$2\")"
480 }
481
482
483 envload() { # load environment from a previous: export > file
484 local file=${1:-$HOME/.${USER}_env}
485 eval "$(export | sed 's/^declare -x/export -n/')"
486 while IFS= read -r line; do
487 # declare -x makes variables local to a function
488 eval ${line/#declare -x/export}
489 done < "$file"
490 }
491
492 f() {
493 # cd forward
494 c +
495 }
496
497 fa() {
498 # find array. make an array of file names found by find into $x
499 # argument: find arguments
500 # return: find results in an array $x
501 while read -rd ''; do
502 x+=("$REPLY");
503 done < <(find "$@" -print0);
504 }
505
506 faf() { # find all files
507 find $@ -type f
508 }
509
510 fastboot() { /a/opt/androidsdk/platform-tools/fastboot "$@"; }
511
512 ff() {
513 if type -P firefox &>/dev/null; then
514 firefox "$@"
515 else
516 iceweasel "$@"
517 fi
518 }
519
520
521
522 fn() {
523 firefox -P alt "$@" >/dev/null 2>&1
524 }
525
526
527 fsdiff () {
528 local missing=false
529 local dname="${PWD##*/}"
530 local m="/a/tmp/$dname-missing"
531 local d="/a/tmp/$dname-diff"
532 [[ -e $d ]] && rm "$d"
533 [[ -e $m ]] && rm "$m"
534 local msize=0
535 local fsfile
536 while read -r line; do
537 fsfile="$1${line#.}"
538 if [[ -e "$fsfile" ]]; then
539 md5diff "$line" "$fsfile" && tee -a "/a/tmp/$dname-diff" <<< "$fsfile $line"
540 else
541 missing=true
542 echo "$line" >> "$m"
543 msize=$((msize + 1))
544 fi
545 done < <(find -type f )
546 if $missing; then
547 echo "$m"
548 (( msize <= 100 )) && cat $m
549 fi
550 }
551 fsdiff-test() {
552 # expected output, with different tmp dirs
553 # /tmp/tmp.HDPbwMqdC9/c/d ./c/d
554 # /a/tmp/tmp.qLDkYxBYPM-missing
555 # ./b
556 cd $(mktemp -d)
557 echo ok > a
558 echo nok > b
559 mkdir c
560 echo ok > c/d
561 local x=$(mktemp -d)
562 mkdir $x/c
563 echo different > $x/c/d
564 echo ok > $x/a
565 fsdiff $x
566 }
567 rename-test() {
568 # test whether missing files were renamed, generally for use with fsdiff
569 # $1 = fsdiff output file, $2 = directory to compare to. pwd = fsdiff dir
570 # echos non-renamed files
571 local x y found
572 unset sums
573 for x in "$2"/*; do
574 { sums+=( "$(md5sum < "$x")" ) ; } 2>/dev/null
575 done
576 while read -r line; do
577 { missing_sum=$(md5sum < "$line") ; } 2>/dev/null
578 renamed=false
579 for x in "${sums[@]}"; do
580 if [[ $missing_sum == "$x" ]]; then
581 renamed=true
582 break
583 fi
584 done
585 $renamed || echo "$line"
586 done < "$1"
587 return 0
588 }
589
590 feh() {
591 # F = fullscren, z = random, Z = auto zoom
592 command feh -FzZ "$@"
593 }
594
595 funce() {
596 # like -e for functions. returns on error.
597 # at the end of the function, disable with:
598 # trap ERR
599 trap 'echo "${BASH_COMMAND:+BASH_COMMAND=\"$BASH_COMMAND\" }
600 ${FUNCNAME:+FUNCNAME=\"$FUNCNAME\" }${LINENO:+LINENO=\"$LINENO\" }\$?=$?"
601 trap ERR
602 return' ERR
603 }
604
605
606 fw() {
607 firefox -P default "$@" >/dev/null 2>&1
608 }
609
610 getdir () {
611 local help="Usage: getdir [--help] PATH
612 Output the directory of PATH, or just PATH if it is a directory."
613 if [[ $1 == --help ]]; then
614 echo "$help"
615 return 0
616 fi
617 if [[ $# -ne 1 ]]; then
618 echo "getdir error: expected 1 argument, got $#"
619 return 1
620 fi
621 if [[ -d $1 ]]; then
622 echo "$1"
623 else
624 local dir="$(dirname "$1")"
625 if [[ -d $dir ]]; then
626 echo "$dir"
627 else
628 echo "getdir error: directory does not exist"
629 return 1
630 fi
631 fi
632 }
633
634 git_empty_branch() { # start an empty git branch. carefull, it deletes untracked files.
635 [[ $# == 1 ]] || { echo 'need a branch name!'; return 1;}
636 local gitroot
637 gitroot || return 1 # function to set gitroot
638 builtin cd "$gitroot"
639 git symbolic-ref HEAD refs/heads/$1
640 rm .git/index
641 git clean -fdx
642 }
643
644 gitroot() {
645 local help="Usage: gitroot [--help]
646 Print the full path to the root of the current git repo
647
648 Handles being within a .git directory, unlike git rev-parse --show-toplevel,
649 and works in older versions of git which did not have that."
650 if [[ $1 == --help ]]; then
651 echo "$help"
652 return
653 fi
654 local p=$(git rev-parse --git-dir) || { echo "error: not in a git repo" ; return 1; }
655 [[ $p != /* ]] && p=$PWD
656 echo "${p%%/.git}"
657 }
658
659 gmacs() {
660 # quit will prompt if the program crashes.
661 gdb -ex=r -ex=quit --args emacs "$@"; r;
662 }
663
664 gdkill() {
665 # kill the emacs daemon
666 pk1 emacs --daemon
667 }
668
669 gse() {
670 git send-email --notes '--envelope-sender=<ian@iankelling.org>' \
671 --suppress-cc=self "$@"
672 }
673
674 gr() {
675 grep -iIP --color=auto "$@"
676 }
677
678 grr() {
679 if [[ ${#@} == 1 ]]; then
680 grep -riIP --color=auto "$@" .
681 else
682 grep -riIP --color=auto "$@"
683 fi
684 }
685
686 hstatus() {
687 # do git status on published repos
688 cd /a/bin/githtml
689 for x in !(forks) forks/* ian-specific/*; do
690 cd `readlink -f $x`/..
691 hr
692 echo $x
693 i status
694 cd /a/bin/githtml
695 done
696 }
697
698 hl() { # history limit. Write extra history to archive file.
699 # todo: this is not working or not used currently
700 local max_lines linecount tempfile prune_lines x
701 local harchive="${HISTFILE}_archive"
702 for x in "$HISTFILE" "$harchive"; do
703 [[ -e $x ]] || { touch "$x" && echo "notice from hl(): creating $x"; }
704 if [[ ! $x || ! -e $x || ! -w $x || $(stat -c "%u" "$x") != $EUID ]]; then
705 echo "error in hl: history file \$x:$x no good"
706 return 1
707 fi
708 done
709 history -a # save history
710 max_lines=$HISTFILELINES
711 [[ $max_lines =~ ^[0-9]+$ ]] || { echo "error in hl: failed to get max line count"; return 1; }
712 linecount=$(wc -l < $HISTFILE) # pipe so it doesn't output a filename
713 [[ $linecount =~ ^[0-9]+$ ]] || { echo "error in hl: wc failed"; return 1; }
714 if (($linecount > $max_lines)); then
715 prune_lines=$(($linecount - $max_lines))
716 head -n $prune_lines "$HISTFILE" >> "$harchive" \
717 && sed --follow-symlinks -ie "1,${prune_lines}d" $HISTFILE
718 fi
719 }
720
721 hr() { # horizontal row. used to break up output
722 printf "$(tput setaf 5)â–ˆ$(tput sgr0)%.0s" $(seq $COLUMNS)
723 echo
724 }
725
726 hrcat() { local f; for f; do [[ -f $f ]] || continue; hr; echo "$f"; cat "$f"; done }
727
728
729 i() { git "$@"; }
730 # modified from ~/local/bin/git-completion.bash
731 # other completion commands are mostly taken from bash_completion package
732 complete -o bashdefault -o default -o nospace -F _git i 2>/dev/null \
733 || complete -o default -o nospace -F _git i
734
735 if ! type service &>/dev/null; then
736 service() {
737 echo actually running: systemctl $2 $1
738 systemctl $2 $1
739 }
740 fi
741
742 ic() {
743 # fast commit all
744 git commit -am "$*"
745 }
746
747 idea() {
748 /a/opt/idea-IC-163.7743.44/bin/idea.sh "$@" &r
749 }
750
751 ifn() {
752 # insensitive find
753 find -L . -not \( -name .svn -prune -o -name .git -prune \
754 -o -name .hg -prune \) -iname "*$**" 2>/dev/null
755 }
756
757
758 if [[ $OS == Windows_NT ]]; then
759 # cygstart wrapper
760 cs() {
761 cygstart "$@" &
762 }
763 xp() {
764 explorer.exe .
765 }
766 # launch
767 o() {
768 local x=(*$1*)
769 (( ${#x[#]} > 1 )) && { echo "warning ${#x[#]} matches found"; sleep 1; }
770 cygstart *$1* &
771 }
772 else
773 o() {
774 if type gvfs-open &> /dev/null ; then
775 gvfs-open "$@"
776 else
777 xdg-open "$@"
778 fi
779 # another alternative is run-mailcap
780 }
781 fi
782
783
784
785 istext() {
786 grep -Il "" "$@" &>/dev/null
787 }
788
789 jtail() {
790 journalctl -n 10000 -f "$@" | grep -Evi "^(\S+\s+){4}(sudo|sshd|cron)"
791 }
792
793
794 l() {
795 if [[ $PWD == /[iap] ]]; then
796 command ls -A --color=auto -I lost+found "$@"
797 else
798 command ls -A --color=auto "$@"
799 fi
800 }
801
802
803 lcn() { locate -i "*$**"; }
804
805 lld() { ll -d "$@"; }
806
807 low() { # make filenames all lowercase
808 local x y
809 for x in "$@"; do
810 y=$(tr "[A-Z]" "[a-z]" <<<"$x")
811 [[ $y != $x ]] && mv "$x" "$y"
812 done
813 }
814
815
816
817
818 lower() { # make first letter of filenames lowercase.
819 local x
820 for x in "$@"; do
821 if [[ ${x::1} == [A-Z] ]]; then
822 y=$(tr "[A-Z]" "[a-z]" <<<"${x::1}")"${x:1}"
823 safe_rename "$x" "$y"
824 fi
825 done
826 }
827
828
829 k() { # history search
830 grep -P --binary-files=text "$@" ${HISTFILE:-~/.bash_history} | tail -n 40;
831 }
832
833
834 make-targets() {
835 # show make targets, via http://stackoverflow.com/questions/3063507/list-goals-targets-in-gnu-make
836 make -qp | awk -F':' '/^[a-zA-Z0-9][^$#\/\t=]*:([^=]|$)/ {split($1,A,/ /);for(i in A)print A[i]}'
837 }
838
839
840 mkc() {
841 mkdir "$1"
842 c "$1"
843 }
844
845 mkdir() { command mkdir -p "$@"; }
846
847 pithos() {
848 cd /
849 export PYTHONPATH=/a/opt/Pithosfly
850 python3 -m pithos&r
851 }
852
853 pakaraoke() {
854 # from http://askubuntu.com/questions/456021/remove-vocals-from-mp3-and-get-only-instrumentals
855 pactl load-module module-ladspa-sink sink_name=Karaoke master=alsa_output.usb-Audioengine_Audioengine_D1-00.analog-stereo plugin=karaoke_1409 label=karaoke control=-30
856 }
857
858
859 pfind() { #find *$1* in $PATH
860 [[ $# != 1 ]] && { echo requires 1 argument; return 1; }
861 local pathArray
862 IFS=: pathArray=($PATH); unset IFS
863 find "${pathArray[@]}" -iname "*$1*"
864 }
865
866 pk1() {
867 local pid
868 pid=($(pgrep -f "$*"))
869 case ${#pid[@]} in
870 1)
871 ps -F $pid
872 m kill $pid
873 ;;
874 0) echo "no pid found" ;;
875 *)
876 ps -F ${pid[@]}
877 ;;
878 esac
879 }
880
881 pick-trash() {
882 # trash-restore lists everything that has been trashed at or below CWD
883 # This picks out files just in CWD, not subdirectories,
884 # which also match grep $1, usually use $1 for a time string
885 # which you get from running restore-trash once first
886 local name x ask
887 local nth=1
888 # last condition is to not ask again for ones we skipped
889 while name="$( echo | restore-trash | gr "$PWD/[^/]\+$" | gr "$1" )" \
890 && [[ $name ]] && (( $(wc -l <<<"$name") >= nth )); do
891 name="$(echo "$name" | head -n $nth | tail -n 1 )"
892 read -p "$name [Y/n] " ask
893 if [[ ! $ask || $ask == [Yy] ]]; then
894 x=$( echo "$name" | gr -o "^\s*[0-9]*" )
895 echo $x | restore-trash > /dev/null
896 elif [[ $ask == [Nn] ]]; then
897 nth=$((nth+1))
898 else
899 return
900 fi
901 done
902 }
903
904 postconfin() {
905 local MAPFILE
906 mapfile -t
907 local s
908 [[ $EUID == 0 ]] || s=s
909 $s postconf -ev "${MAPFILE[@]}"
910 }
911
912 pub() {
913 rld /a/h/_site/ li:/var/www/iankelling.org/html
914 }
915
916 pubip() { curl -4s https://icanhazip.com; }
917 whatismyip() { pubip; }
918
919
920 pwgen() {
921 # -m = min length
922 # -x = max length
923 # -t = print pronunciation
924 apg -m 12 -x 16 -t
925 }
926
927
928 q() { # start / launch a program in the backround and redir output to null
929 "$@" &> /dev/null &
930 }
931
932 r() {
933 exit "$@" 2>/dev/null
934 }
935
936 rbpipe() { rbt post -o --diff-filename=- "$@"; }
937 rbp() { rbt post -o "$@"; }
938
939 rl() {
940 # rsync, root is required to keep permissions right.
941 # rsync --archive --human-readable --verbose --itemize-changes --checksum \(-ahvic\) \
942 # --no-times --delete
943 # basically, make an exact copy, use checksums instead of file times to be more accurate
944 rsync -ahvic --delete "$@"
945 }
946 rld() {
947 # like rlu, but don't delete files on the target end which
948 # do not exist on the original end.
949 rsync -ahvic "$@"
950 }
951 complete -F _rsync -o nospace rld rl rlt
952
953 rlt() {
954 # rl without preserving modification time.
955 rsync -ahvic --delete --no-t "$@"
956 }
957
958 rlu() { # [OPTS] HOST PATH
959 # eg rlu -opts frodo /testpath
960 # useful for selectively sending dirs which have been synced with unison,
961 # where the path is the same on both hosts.
962 opts=("${@:1:$#-2}") # 1 to last -2
963 path="${@:$#}" # last
964 host="${@:$#-1:1}" # last -1
965 if [[ $path == .* ]]; then echo error: need absolut path; return 1; fi
966 # rync here uses checksum instead of time so we don't mess with
967 # unison relying on time as much. g is for group, same reason
968 # to keep up with unison.
969 s rsync -rlpchviog --relative "${opts[@]}" "$path" "root@$host:/";
970 }
971
972
973 rspicy() { # usage: HOST DOMAIN
974 # connect to spice vm remote host. use vspicy for local host
975 local port=$(ssh $1<<EOF
976 sudo virsh dumpxml $2|grep "<graphics.*type='spice'" | \
977 sed -rn "s/.*port='([0-9]+).*/\1/p"
978 EOF
979 )
980 if [[ $port ]]; then
981 spicy -h $1 -p $port
982 else
983 echo "error: no port found. check that the domain is running."
984 fi
985 }
986
987 s() {
988 # background
989 # I use a function because otherwise we can't use in a script,
990 # can't assign to variable.
991 #
992 # note: gksudo is recommended for X apps because it does not set the
993 # home directory to the same, and thus apps writing to ~ fuck things up
994 # with root owned files.
995 #
996 if [[ $EUID != 0 || $1 == -* ]]; then
997 SUDOD="$PWD" sudo -i "$@"
998 else
999 "$@"
1000 fi
1001 }
1002
1003 safe_rename() {
1004 if [[ $# != 2 ]]; then
1005 echo safe_rename error: $# args, need 2 >2
1006 return 1
1007 elif [[ $1 != $2 ]]; then
1008 if [[ -e $2 ]]; then
1009 echo Cannot rename "$1" to "$2" as it already exists.
1010 else
1011 mv "$1" "$2"
1012 fi
1013 fi
1014 }
1015
1016
1017 sb() { # sudo bash -c
1018 # use sb instead of s is for sudo redirections,
1019 # eg. sb 'echo "ok fine" > /etc/file'
1020 local SUDOD="$PWD"
1021 sudo -i bash -c "$@"
1022 }
1023 complete -F _root_command s sb
1024
1025 scssl() {
1026 # s gem install scss-lint
1027 pushd /a/opt/thoughtbot-guides
1028 git pull --stat
1029 popd
1030 scss-lint -c /a/opt/thoughtbot-guides/style/sass/.scss-lint.yml "$@"
1031 }
1032
1033 ser() {
1034 local s; [[ $EUID != 0 ]] && s=sudo
1035 if type -p systemctl &>/dev/null; then
1036 $s systemctl $1 $2
1037 else
1038 $s service $2 $1
1039 fi
1040 }
1041
1042 sgo() { # service go
1043 service=$1
1044 ser restart $service
1045 if type -p systemctl &>/dev/null; then
1046 ser enable $service
1047 fi
1048 }
1049
1050
1051 shellck() {
1052 # 2086 = unquoted $var
1053 # 2046 = unquoted $(cmd)
1054 # i had -x as an arg, but debian testing(stretch) doesn't support it
1055 shellcheck -e 2086,2046,2068,2006,2119 "$@"
1056 }
1057
1058
1059 slog() {
1060 # log with script. timing is $1.t and script is $1.s
1061 # -l to save to ~/typescripts/
1062 # -t to add a timestamp to the filenames
1063 local logdir do_stamp arg_base
1064 (( $# >= 1 )) || { echo "arguments wrong"; return 1; }
1065 logdir="/a/dt/"
1066 do_stamp=false
1067 while getopts "lt" option
1068 do
1069 case $option in
1070 l ) arg_base=$logdir ;;
1071 t ) do_stamp=true ;;
1072 esac
1073 done
1074 shift $(($OPTIND - 1))
1075 arg_base+=$1
1076 [[ -e $logdir ]] || mkdir -p $logdir
1077 $do_stamp && arg_base+=$(date +%F.%T%z)
1078 script -t $arg_base.s 2> $arg_base.t
1079 }
1080 splay() { # script replay
1081 #logRoot="$HOME/typescripts/"
1082 #scriptreplay "$logRoot$1.t" "$logRoot$1.s"
1083 scriptreplay "$1.t" "$1.s"
1084 }
1085
1086 sr() {
1087 # sudo redo. be aware, this command may not work right on strange distros or earlier software
1088 if [[ $# == 0 ]]; then
1089 sudo -E bash -c -l "$(history -p '!!')"
1090 else
1091 echo this command redos last history item. no argument is accepted
1092 fi
1093 }
1094
1095 srm () {
1096 # with -ll, less secure but faster.
1097 command srm -ll "$@"
1098 }
1099
1100 srun() {
1101 scp $2 $1:/tmp
1102 ssh $1 /tmp/${2##*/} "${@:2}"
1103 }
1104
1105 swap() {
1106 local tmp
1107 tmp=$(mktemp)
1108 mv $1 $tmp
1109 mv $2 $1
1110 mv $tmp $2
1111 }
1112
1113 t() {
1114 local x
1115 local -a args
1116 if type -t trash-put >/dev/null; then
1117 # skip args that don't exist, or else trash-put will have an error
1118 for x in "$@"; do
1119 if [[ -e $x || -L $x ]]; then
1120 args+=("$x")
1121 fi
1122 done
1123 [[ ! ${args[@]} ]] || trash-put "${args[@]}"
1124 else
1125 rm -rf "$@"
1126 fi
1127 }
1128
1129
1130 tclock() {
1131 clear
1132 date +%l:%_M
1133 len=60
1134 # this goes to full width
1135 #len=${1:-$((COLUMNS -7))}
1136 x=1
1137 while true; do
1138 if (( x == len )); then
1139 end=true
1140 d="$(date +%l:%_M) "
1141 else
1142 end=false
1143 d=$(date +%l:%M:%_S)
1144 fi
1145 echo -en "\r"
1146 echo -n "$d"
1147 for ((i=0; i<x; i++)); do
1148 if (( i % 6 )); then
1149 echo -n _
1150 else
1151 echo -n .
1152 fi
1153 done
1154 if $end; then
1155 echo
1156 x=1
1157 else
1158 x=$((x+1))
1159 fi
1160 sleep 5
1161 done
1162 }
1163
1164
1165 te() {
1166 # test existence / exists
1167 local ret=0
1168 for x in "$@"; do
1169 [[ -e "$x" || -L "$x" ]] || ret=1
1170 done
1171 return $ret
1172 }
1173
1174 testmail() {
1175 declare -gi _seq; _seq+=1
1176 echo "test body" | m mail -s "test mail from $HOSTNAME, $_seq" "${1:-root@localhost}"
1177 }
1178
1179 tm() {
1180 # timer in minutes
1181 (sleep $(calc "$@ * 60") && mpv --volume 50 /a/bin/data/alarm.mp3 --loop=no) > /dev/null 2>&1 &
1182 }
1183
1184
1185 tu() {
1186 local s;
1187 local dir="$(dirname "$1")"
1188 if [[ -e $1 && ! -w $1 || ! -w $(dirname "$1") ]]; then
1189 s=s;
1190 fi
1191 $s teeu "$@"
1192 }
1193
1194 tx() { # toggle set -x, and the prompt so it doesn't spam
1195 if [[ $- == *x* ]]; then
1196 set +x
1197 PROMPT_COMMAND=prompt_command
1198 else
1199 unset PROMPT_COMMAND
1200 PS1="\w \$ "
1201 set -x
1202 fi
1203 }
1204
1205 psnetns() {
1206 # show all processes in the network namespace $1.
1207 # blank entries appear to be subprocesses/threads
1208 local x netns
1209 netns=$1
1210 ps -w | head -n 1
1211 s find -L /proc/[1-9]*/task/*/ns/net -samefile /run/netns/$netns | cut -d/ -f5 | \
1212 while read l; do
1213 x=$(ps -w --no-headers -p $l);
1214 if [[ $x ]]; then echo "$x"; else echo $l; fi;
1215 done
1216 }
1217
1218 m() { printf "%s\n" "$*"; "$@"; }
1219
1220 vpnbash() {
1221 m s nsenter -t $(pgrep openvpn) -n -m bash
1222 # note, if we wanted to run a graphical program,
1223 # instead of bash, we could use
1224 # gksudo -u ${SUDO_USER:-$USER} "$@"
1225 }
1226
1227
1228 trg() { transmission-remote-gtk&r; }
1229
1230 # transmission() {
1231 # local pid=$(cat /var/lib/transmission-daemon/transmission-daemon.pid)
1232 # if [[ $pid && -e /proc/$pid ]]; then
1233 # echo "noop. already running."
1234 # return
1235 # fi
1236
1237 # local NAME=transmission-daemon
1238 # local DAEMON=/usr/bin/$NAME
1239 # local duser=debian-transmission
1240
1241 # [ -e /etc/default/$NAME ] && . /etc/default/$NAME
1242 # s ip netns exec vpn sudo -u $duser ionice -c 3 nice -n 19 $DAEMON $OPTIONS
1243 # }
1244
1245 virshrm() {
1246 for x in "$@"; do virsh destroy "$x"; virsh undefine "$x"; done
1247 }
1248
1249 vm-set-listen(){
1250 local t=$(mktemp)
1251 local vm=$1
1252 local ip=$2
1253 s virsh dumpxml $vm | sed -r "s/(<listen.*address=')([^']+)/\1$ip/" | \
1254 sed -r "s/listen='[^']+/listen='$ip/"> $t
1255 s virsh undefine $vm
1256 s virsh define $t
1257 }
1258
1259
1260 vmshare() {
1261 vm-set-listen $1 0.0.0.0
1262 }
1263
1264
1265 vmunshare() {
1266 vm-set-listen $1 127.0.0.1
1267 }
1268
1269 vpn() {
1270 s systemctl start openvpn@client&
1271 journalctl --unit=openvpn@client -f -n0
1272 }
1273
1274
1275 vpnoff() {
1276 s systemctl stop openvpn@client
1277 }
1278
1279
1280 vrm() {
1281 virsh destroy $1
1282 virsh undefine $1
1283 }
1284
1285
1286
1287 vspicy() { # usage: VIRSH_DOMAIN
1288 # connect to vms made with virt-install
1289 spicy -p $(sudo virsh dumpxml "$1"|grep "<graphics.*type='spice'"|\
1290 sed -r "s/.*port='([0-9]+).*/\1/")
1291 }
1292
1293
1294 whatismyip() { curl ipecho.net/plain ; echo; }
1295
1296
1297 #############################
1298 ######### misc stuff ########
1299 #############################
1300
1301 if [[ $- == *i* ]]; then
1302 # commands to run when bash exits normally
1303 trap "hl" EXIT
1304 fi
1305
1306
1307 # temporary variables to test colorization
1308 # some copied from gentoo /etc/bash/bashrc,
1309 use_color=false
1310 # dircolors --print-database uses its own built-in database
1311 # instead of using /etc/DIR_COLORS. Try to use the external file
1312 # first to take advantage of user additions.
1313 safe_term=${TERM//[^[:alnum:]]/?} # sanitize TERM
1314 match_lhs=""
1315 [[ -f ~/.dir_colors ]] && match_lhs="${match_lhs}$(<~/.dir_colors)"
1316 [[ -f /etc/DIR_COLORS ]] && match_lhs="${match_lhs}$(</etc/DIR_COLORS)"
1317 [[ -z ${match_lhs} ]] \
1318 && type -P dircolors >/dev/null \
1319 && match_lhs=$(dircolors --print-database)
1320 # test if our $TERM is in the TERM values in dircolor
1321 [[ $'\n'${match_lhs} == *$'\n'"TERM "${safe_term}* ]] && use_color=true
1322
1323
1324 if ${use_color} && [[ $- == *i* ]]; then
1325
1326 if [[ $XTERM_VERSION == Cygwin* ]]; then
1327 get_term_color() {
1328 for x in "$@"; do
1329 case $x in
1330 underl) echo -n $'\E[4m' ;;
1331 bold) echo -n $'\E[1m' ;;
1332 red) echo -n $'\E[31m' ;;
1333 green) echo -n $'\E[32m' ;;
1334 blue) echo -n $'\E[34m' ;;
1335 cyan) echo -n $'\E[36m' ;;
1336 yellow) echo -n $'\E[33m' ;;
1337 purple) echo -n $'\E[35m' ;;
1338 nocolor) echo -n $'\E(B\E[m' ;;
1339 esac
1340 done
1341 }
1342
1343 else
1344 get_term_color() {
1345 for x in "$@"; do
1346 case $x in
1347 underl) echo -n $(tput smul) ;;
1348 bold) echo -n $(tput bold) ;;
1349 red) echo -n $(tput setaf 1) ;;
1350 green) echo -n $(tput setaf 2) ;;
1351 blue) echo -n $(tput setaf 4) ;;
1352 cyan) echo -n $(tput setaf 6) ;;
1353 yellow) echo -n $(tput setaf 3) ;;
1354 purple) echo -n $(tput setaf 5) ;;
1355 nocolor) echo -n $(tput sgr0) ;; # no font attributes
1356 esac
1357 done
1358 }
1359 fi
1360 else
1361 get_term_color() {
1362 :
1363 }
1364 fi
1365 # Try to keep environment pollution down, EPA loves us.
1366 unset safe_term match_lhs use_color
1367
1368
1369
1370
1371
1372
1373 ###############
1374 # prompt ######
1375 ###############
1376
1377
1378 if [[ $- == *i* ]]; then
1379 # git branch/status prompt function
1380 if [[ $OS != Windows_NT ]]; then
1381 GIT_PS1_SHOWDIRTYSTATE=true
1382 fi
1383 # arch source lopip show -fcation
1384 [[ -r /usr/share/git/git-prompt.sh ]] && source /usr/share/git/git-prompt.sh
1385 # fedora/debian source
1386 [[ -r /usr/share/git-core/contrib/completion/git-prompt.sh ]] && source /usr/share/git-core/contrib/completion/git-prompt.sh
1387
1388 # in case we didn't source git-prompt.sh
1389 if ! declare -f __git_ps1 > /dev/null; then
1390 __git_ps1() {
1391 :
1392 }
1393 fi
1394
1395 # this needs to come before next ps1 stuff
1396 # this stuff needs bash 4, feb 2009,
1397 # old enough to no longer condition on $BASH_VERSION anymore
1398 shopt -s autocd
1399 shopt -s dirspell
1400 PS1='\w'
1401 if [[ $- == *i* ]] && [[ ! $RLC_INSIDE_EMACS ]]; then
1402 PROMPT_DIRTRIM=2
1403 bind -m vi-command B:shell-backward-word
1404 bind -m vi-command W:shell-forward-word
1405 fi
1406
1407 if [[ $SSH_CLIENT ]]; then
1408 PS1="\h $PS1"
1409 fi
1410
1411 prompt_command() {
1412 local return=$? # this MUST COME FIRST
1413 local psc pst ps_char ps_color stale_subvol
1414 unset IFS
1415 history -a # save history
1416
1417 # for titlebar
1418 if [[ ! $DESKTOP_SESSION == xmonad && $TERM == *(screen*|xterm*|rxvt*) ]]; then
1419 # from the screen man page
1420 if [[ $TERM == screen* ]]; then
1421 local title_escape="\033]..2;"
1422 else
1423 local title_escape="\033]0;"
1424 fi
1425 echo -ne "$title_escape${PWD/#$HOME/~} $USER@$HOSTNAME\007"
1426 fi
1427
1428
1429 case $return in
1430 0) ps_color="$(get_term_color blue)"
1431 ps_char='\$'
1432 ;;
1433 1) ps_color="$(get_term_color green)"
1434 ps_char="$return \\$"
1435 ;;
1436 *) ps_color="$(get_term_color yellow)"
1437 ps_char="$return \\$"
1438 ;;
1439 esac
1440 if [[ ! -O . ]]; then # not owner
1441 if [[ -w . ]]; then # writable
1442 ps_color="$(get_term_color bold red)"
1443 else
1444 ps_color="$(get_term_color bold green)"
1445 fi
1446 fi
1447 # I would set nullglob, but bash has had bugs where that
1448 # doesn't work if not in top level.
1449 if [[ -e /nocow/btrfs-stale ]] && ((`ls -AUq /nocow/btrfs-stale|wc -l`)); then
1450 ps_char="! $ps_char"
1451 fi
1452 PS1="${PS1%"${PS1#*[wW]}"} \[$ps_color\]$ps_char\[$(get_term_color nocolor)\] "
1453 # emacs completion doesn't like the git prompt atm, so disabling it.
1454 #PS1="${PS1%"${PS1#*[wW]}"}$(__git_ps1 ' (%s)') \[$ps_color\]$ps_char\[$(get_term_color nocolor)\] "
1455 }
1456 PROMPT_COMMAND=prompt_command
1457 fi
1458
1459
1460
1461 ###########################################
1462 # stuff that makes sense to be at the end #
1463 ###########################################
1464 if [[ "$SUDOD" ]]; then
1465 cd "$SUDOD"
1466 unset SUDOD
1467 elif [[ -d /a ]] && [[ $PWD == $HOME ]] && [[ $- == *i* ]]; then
1468 cd /a
1469 fi
1470
1471
1472 # best practice
1473 unset IFS
1474
1475
1476 # if someone exported $SOE, catch errors
1477 if [[ $SOE ]]; then
1478 errcatch
1479 fi
1480
1481 # I'd prefer to have system-wide, plus user ruby, due to bug in it
1482 # https://github.com/rubygems/rubygems/pull/1002
1483 # further problems: installing multi-user ruby and user ruby,
1484 # you don't get multi-user ruby when you sudo to root, unless its sudo -i.
1485 # There a third hybrid form, which passenger error suggested I use,
1486 # but it didn't actually work.
1487
1488 # in cased I never need this
1489 # rvm for non-interactive shell: modified from https://rvm.io/rvm/basics
1490 #if [[ $(type -t rvm) == file && ! $(type -t ruby) ]]; then
1491 # source $(rvm 1.9.3 do rvm env --path)
1492 #fi
1493
1494 # based on warning from rvmsudo
1495 export rvmsudo_secure_path=1
1496
1497 # for other script I wrote
1498 #export ACME_TINY_PATH=/a/opt/acme-tiny
1499 export ACME_TINY_WRAPPER_CERT_DIR=/p/c/machine_specific/$HOSTNAME/webservercerts
1500
1501 if [[ -s "/usr/local/rvm/scripts/rvm" ]]; then
1502 source "/usr/local/rvm/scripts/rvm"
1503 elif [[ -s $HOME/.rvm/scripts/rvm ]]; then
1504 source $HOME/.rvm/scripts/rvm
1505 fi
1506
1507
1508 path_add --end ~/.npm-global
1509
1510
1511 # didn't get drush working, if I did, this seems like the
1512 # only good thing to include for it.
1513 # Include Drush completion.
1514 # if [ -f "/home/ian/.drush/drush.complete.sh" ] ; then
1515 # source /home/ian/.drush/drush.complete.sh
1516 # fi
1517
1518
1519 # https://wiki.archlinux.org/index.php/Xinitrc#Autostart_X_at_login
1520 # i added an extra condition as gentoo xorg guide says depending on
1521 # $DISPLAY is fragile.
1522 if [[ ! $DISPLAY && $XDG_VTNR == 1 ]] && shopt -q login_shell && isarch; then
1523 exec startx
1524 fi
1525
1526
1527 # ensure no bad programs appending to this file will have an affect
1528 return 0