~e-carlin/home-env

ref: 595622509b7a8d3253cbafdf7f2c788adae5df7d home-env/bashrc.d/bash-aliases.sh -rw-r--r-- 3.8 KiB
59562250 — git-user for now output images inside of notebook; make var nil if want to use mailcap a month ago
                                                                                
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
alias d_container_id="docker ps | cut -f1 -d ' ' | awk 'NR==2{printf \"%s\", \$1}' | xclip -selection c"
alias g_files_in_commit="git diff-tree --no-commit-id --name-only -r"
alias gbg="git branch | grep -i"
alias gch="git checkout"
alias gd="git diff --color"
alias glg="git log --graph --decorate --simplify-by-decoration --oneline"
alias gll="git log --abbrev-commit --pretty=oneline"
alias gl="gll | head"
alias gg="git status"
alias k="clear"
alias grep="grep --color=auto"
alias reset_keymap="setxkbmap -layout us"
alias sbp="source ~/.bash_profile"

# macOS uses BSD ls try to use GNU ls which long options
if ! ls --color=auto &> /dev/null && [ ! -s /usr/local/opt/coreutils/libexec/gnubin/ls ]; then
    echo '** only BSD `ls` found. Maybe run `brew install coreutils` **'
else
    alias gls='ls --color=auto'
    [ -s /usr/local/opt/coreutils/libexec/gnubin/ls ] && alias gls='/usr/local/opt/coreutils/libexec/gnubin/ls --color=auto'
    alias la="gls -A"
    alias ll='gls -lah --hide="*.pyc"'
fi

# From: https://github.com/biviosoftware/home-env/blob/master/bashrc.d/zz-10-base.sh#L296
function g() {
    local x="$1"
    shift
    # *~ is emacs backup file
    # #* is emacs autosave file
    grep -iIrn --exclude-dir='.git' --exclude='*~' --exclude='#*' \
       "$x" "${@-.}"   2>/dev/null
}
export -f g

function g_delete_branches() {
    if [[ $1 == '-c' ]]; then
        git checkout master && git branch --merged | egrep -v "(^\*|master)" | xargs git branch -d
        git remote prune origin
    else
        git checkout master && git branch --merged | egrep -v "(^\*|master)"
    fi
}
export -f g_delete_branches

function g_parent() {
    # Find the name of the nearest "parent" branch
    # https://stackoverflow.com/a/17843908/5518313
    git show-branch \
        | sed "s/].*//" \
        | grep "\*" \
        | grep -v "$(git rev-parse --abbrev-ref HEAD)" \
        | head -n1 \
        | sed "s/^.*\[//"
}
export -f g_parent

function gb() {
    PS3="Enter number of branch to checkout: "
    # Need to use --format because normal `git branch` shows a * next to the
    # current branch which will be expanded by bash to list files in $PWD
    select b in $(git branch --format='%(refname:short)' --sort=committerdate)
    do
        gch "$b"
        break
    done
}
export -f gb

function gcam() {
    git commit -a -m "$*"
}
export -f gcam

function gp() {
    if git push "$@" ; then
        return
    fi
    local b=$(git rev-parse --abbrev-ref HEAD)
    if ! git config --get "branch.$b.merge" ; then
        git push --set-upstream origin "$b"
    fi
}
export -f gp

function gpy() {
    # can't use g() because --exclude's override --include
    grep -iIrn$2 --include="*.py" "$1"  .
}
export -f gpy


function gext() {
    g "$1"  --exclude-dir="ext" --exclude-dir="node_modules" .
}
export -f gext

#TODO(e-carlin): this doesn't work right on macos
function gps() {
    local x=$1
    ps auxww | grep -i "[${x:0:1}]${x[@]:1}"
}
export -f gps

function gsump() {
   g --exclude-dir="Arduino" "$@"
}
export -f gsump

#TODO(e-carlin): this doesn't work right on macos
function pstree() {
    ps axf
}
export -f pstree

function pscpu(){
    ps auxww --sort=-pcpu | head -n 10
}
export -f pscpu

function findd() {
    find . -type f -name "$1" -exec rm -f '{}' \;
}
export -f findd

function findn() {
    local path="$1"
    local name="$2"
    if [[ -z "$2" ]]; then
        path="."
        name="$1"
    fi
    # stderr redirection makes it so permission denied errors are not displayed
   find "$path" -ipath "*$name*" -not -name "*.pyc" -not -type d 2>/dev/null
}
export -f findn

function findsr() {
    findn ~/src/radiasoft/sirepo/run "$1*/sirepo-data.json"
}
export -f findsr

function sirepo_pr_comments() {
    curl -s "https://api.github.com/repositories/37476480/pulls/$1/comments" | jq .[].body | sed G > c.txt
    echo 'results in c.txt'
}
export -f sirepo_pr_comments