summaryrefslogtreecommitdiff
path: root/bash_aliases
blob: 2bbacc9800d6ef586e563179931da2ff44114bd4 (plain)
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
# various 'ls' improvements
alias ls="ls --color=auto --quoting-style=literal"
alias ll="ls -l --color=auto --quoting-style=literal"
alias l='ls --color=auto -lhog --file-type -X --group-directories-first --quoting-style=literal'
alias la='ls -A'

# Various grep improvements
alias egrep='grep -E --color=auto'
alias fgrep='grep -F --color=auto'
alias grep='grep --color=auto'

# Force colored group output even when outputing to non-terminal.
# allows piping color greps:
#    cat FOO | redgrep BAR | redgrep BAZ
# (of course, if the ANSI markings mess-up the text, it won't be matched)
alias greengrep='GREP_COLORS="ms=1;32" grep --color=always'
alias redgrep='GREP_COLORS="ms=1;31" grep --color=always'
alias pinkgrep='GREP_COLORS="ms=1;35" grep --color=always'
alias yellowgrep='GREP_COLORS="ms=1;33" grep --color=always'


# Pretest ssh/scp
alias ussh="ssh -o StrictHostKeyChecking=no -o CheckHostIP=no -o UserKnownHostsFile=/dev/null"
alias uscp="scp -o StrictHostKeyChecking=no -o CheckHostIP=no -o UserKnownHostsFile=/dev/null"

# Pretest list of running VMs
ptl()
{
    ps ax \
       | grep qemu-system \
       | grep hostfwd \
       | ( printf "Pid\tPort\tVM\n" ; \
           perl -ne '($pid) = /^ *(\d+)/; ($v) = /-name ([^ ]+)/;
                     ($p) = /hostfwd=tcp:127\.0\.0\.1:(\d+)/ ;
                     print "$pid\t$p\t$v\n" ;' )
}

# GitK gui with all branches in the background
alias gitka='nohup gitk --all &'

alias topu="top -u $USER"

# indent and copy to X clipboard (for markdown paste)
if which xsel 1>/dev/null 2>/dev/null ; then
	# On unix
	mdxcp()
	{
	    sed 's/^/    /' | xsel -b
	}
elif which pbcopy 1>/dev/null 2>/dev/null ; then
	# On macs
	mdxcp()
	{
	    sed 's/^/    /' | pbcopy
	}
fi

# List only directories (in current directory or in specified path)
# without recursion.
lsd()
{
    find ${1:-.} -maxdepth 1 -mindepth 1 -type d -print0 \
        | xargs -0 ls -ld --color=auto
}

# Quickly edit Markdown files using nano
# (requires nano settings from http://crashcourse.housegordon.org/nano.html)
alias mdnano='nano -E -T 4 -Y markdown -r 78'

# Simple HTTP server from current directory
# optionally add port number
alias webserve='python -m SimpleHTTPServer'

# Emacs (no-X) shortcut
alias em='emacs -nw'

# Generate a password.
# Using hsxkpasswd from http://www.bartb.ie/xkpasswd .
# install with: `cpan -i Crypt::HSXKPasswd`
if which hsxkpasswd 1>/dev/null 2>/dev/null ; then
	alias passgen='hsxkpasswd -p APPLEID'
fi

# df on local physical drives (no network drives, no tmpfs mounts)
alias dff='df -l -h -x tmpfs -x devtmpfs'

##
## send a file to pastegin
##
pastegin()
{
    FILE="$1"
    test -z "$FILE" && { echo "missing file to upload" >&2 ; return 1 ; }
    test -e "$FILE" || { echo "file '$FILE' not found" >&2 ; return 1 ; }
    test -r "$FILE" || { echo "file '$FILE' not a regular file" >&2 ; return 1 ; }

    URL=$(curl -k -F "a=@$FILE" https://pastegin.housegordon.org/) \
        || { echo "failed to upload '$FILE' to pastegin" >&2 ; return 1 ; }

    echo "$URL" | sed 's/^http:/https:/'
}

## JQ - the JSON command-line manipular.
## jql - jq into LESS (with colors)
if which jq 1>/dev/null 2>/dev/null ; then
    jql ()
    {
        if test -n "$1"; then
            jq -C . "$1" | less -Sr;
        else
            jq -C . | less -Sr;
        fi
    }
fi


## Any local overriding aliases
if test -e "$HOME/.bash_aliases_local" ; then
    . "$HOME/.bash_aliases_local"
fi


# Unicode helper, print input in octals
alias uod='LC_ALL=C od -An -c'

# From GNU Coding-Standard guidelines
# https://www.gnu.org/prep/standards/html_node/Formatting.html
alias gnuindent='indent -nbad -bap -nbc -bbo -bl -bli2 -bls -ncdb -nce -cp1 -cs -di2 -ndj -nfc1 -nfca -hnl -i2 -ip5 -lp -pcs -psl -nsc -nsob'