aboutsummaryrefslogtreecommitdiffstats
path: root/bash/.bashrc
blob: a4c9d6f2070cc809d9a814f13504eaef72bea14c (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
# .bashrc
#
# note: this file is executed by interactive non-login shell
#       if it needs to execute for login shells too (i.e. virtual
#       tty) see .bash_profile. something like the following may
#       work: test -f ~/.bashrc && . ~/.bashrc

LC_ALL="en_US.UTF-8"
# This PS1 is completed at the end, allowing statuses to be included between the directory and closing $
PS1="[\u@\[\e[38;5;148m\]\h\[\e[m\]:\[\e[36m\]\W\[\e[m\]\[\e[m\]]\[\e[m\]"
END_PS1="\$\[\e[m\] "
# This is the original PS1
#PS1="[\u@\[\e[38;5;148m\]\h\[\e[m\]:\[\e[36m\]\W\[\e[m\]\[\e[m\]]\[\e[m\]\$\[\e[m\] "
PATH="${HOME}/bin:${HOME}/.local/bin:${PATH}"

# OpenBSD
# FreeBSD
# Darwin
# Linux
OS_NAME=`uname`

# Disable bash deprecation warning on OS X
if [ "$OS_NAME" == "Darwin" ]; then
    export BASH_SILENCE_DEPRECATION_WARNING=1
fi
# Disable AWS SAM Telemetry
export SAM_CLI_TELEMETRY=0

# Enable starship if possible
STARSHIP=`which starship 2> /dev/null`
if [ -x "$STARSHIP" ]; then
    eval "$(starship init bash)"
fi

# Enable flutter
if [ -d "$HOME/bin/flutter/" ]; then
    PATH="${HOME}/bin/flutter/bin:${PATH}"
    export CHROME_EXECUTABLE=chromium
fi

# Enable android studio
if [ -d "$HOME/bin/android-studio/bin" ]; then
    PATH="${HOME}/bin/android-studio/bin:${PATH}"
    export JAVA_HOME="${HOME}/bin/android-studio/jre"
fi

# Set the AndroidSDK path
if [ -d "$HOME/.AndroidSDK" ]; then
    export ANDROID_SDK_ROOT=$HOME/.AndroidSDK/
    PATH=$HOME/.AndroidSDK/tools/bin:$PATH
fi

# Erlang/Kerl
KERL=`which kerl 2> /dev/null`
if [ -x "$KERL" ]; then
    # kerl breaks the manpath
    if [ "$OS_NAME" != "Darwin" ]; then
        export MANPATH=$(grep manpath /etc/man.conf | awk '{ print $2 }' | paste -s -d:)
    fi
    if [ -f $HOME/.config/bash_completions/kerl ]; then
        . $HOME/.config/bash_completions/kerl
    fi
    if [ "$OS_NAME" == "Darwin" ]; then
        export KERL_BUILD_BACKEND="git"
        export KERL_CONFIGURE_OPTIONS="--disable-hipe --without-javac --with-dynamic-trace=dtrace"
    fi
    if [ "$OS_NAME" == "Linux" ]; then
        export KERL_BUILD_BACKEND="git"
        export KERL_CONFIGURE_OPTIONS="--without-javac --with-dynamic-trace=systemtap"
    fi
fi

if [ -d "$HOME/.virtualenvs/erlang" ]; then
    . ~/.virtualenvs/erlang/activate
fi
ERL=`which erl 2> /dev/null`
if [ -x "$ERL" ]; then
    # +pc unicode                    Output strings as unicode by default
    # -kernal shell_history enabled  Enable erl repl history
    export ERL_AFLAGS="+pc unicode -kernel shell_history enabled"
fi

# Enable rust and cargo
# if [ -x $HOME/.cargo/bin/cargo ]; then
#     PATH="${HOME}/.cargo/bin:${PATH}"
# fi
if [ -f "$HOME/.cargo/env" ]; then
    source "$HOME/.cargo/env"
fi

# Enable nodejs
#if [ -d /usr/local/lib/nodejs ]; then
#  NJS_VERSION=v16.8.0
#  NJS_DISTRO=linux-x64
#  PATH=/usr/local/lib/nodejs/node-$NJS_VERSION-$NJS_DISTRO/bin:$PATH
#fi

# Enable go
if [ -d /usr/local/go/bin ]; then
    PATH=$PATH:/usr/local/go/bin
fi

#######

# Docker/Podman

DOCKER_PATH=`which docker 2> /dev/null`
PODMAN_PATH=`which podman 2> /dev/null`
#echo $PODMAN_PATH
#if [ -n "$PODMAN_PATH" ]; then
#    source <(podman completion bash)
#    # Enable docker if it's podman
#    if [ -z $DOCKER_PATH ]; then
#        alias docker=podman
#    fi
#fi

# Enable docker completions on OS X
if [ -n $DOCKER_PATH ] && [ -d /Applications/Docker.app/Contents/Resources/etc/ ]; then
    # Docker for Mac seems to switch the filenames sometimes.
    if [ -f /Applications/Docker.app/Contents/Resources/etc/docker ]; then
        . /Applications/Docker.app/Contents/Resources/etc/docker
    elif [ -f /Applications/Docker.app/Contents/Resources/etc/docker-compose.bash-completion ]; then
        . /Applications/Docker.app/Contents/Resources/etc/docker-compose.bash-completion
    fi
    . /Applications/Docker.app/Contents/Resources/etc/docker-compose.bash-completion
fi

#######

# Nix

# Enable nix
if [ -f $HOME/.nix-profile/etc/profile.d/nix.sh ]; then
    . $HOME/.nix-profile/etc/profile.d/nix.sh
fi

#######

# Homebrew

# Enable Homebrew
if [ -x /opt/homebrew/bin/brew ]; then
    export HOMEBREW_NO_ANALYTICS=1
    #export LDFLAGS="-L/opt/homebrew/lib"
    #export CPPFLAGS="-I/opt/homebrew/include"
    eval "$(/opt/homebrew/bin/brew shellenv)"

    # Enable bash-completions for homebrew installed bash
    if [ -f /opt/homebrew/etc/bash_completion ]; then
        . /opt/homebrew/etc/bash_completion
    fi


    # Enable pyenv
    if [ -x /opt/homebrew/bin/pyenv ]; then
        # Prevent linking against system libpython when building
        alias brew='env PATH="${PATH//$(pyenv root)\/shims:/}" brew'
        export PYENV_ROOT="$HOME/.pyenv"
        export PATH="$PYENV_ROOT/bin:$PATH"
        eval "$(pyenv init --path)"
        eval "$(pyenv init -)"
    fi
fi

#if [[ -x /usr/local/bin/pyenv || -x $HOME/bin/pyenv ]]; then
#    # FreeBSD, probably linux
#    eval "$(pyenv init -)"
#fi

# Default install instructions
if [[ -x $HOME/.pyenv/bin ]]; then
    eval "$($HOME/.pyenv/bin/pyenv init -)"
    export PATH=$HOME/.pyenv/bin:$PATH
fi

function install-pylsp() {
    # a little shortcut for installing the helpers i use for python
    # IDE features
    [ ! -z "${VIRTUAL_ENV}" ] \
        && pip install -U --upgrade-strategy eager \
               black \
               flake8 \
               flake8-docstrings \
               flake8-import-order \
               mypy \
               jedi-language-server \
        || echo 'Not in a venv.'
}

__workon() {
    source ~/.virtualenvs/$1/bin/activate
}
__mkvirtualenv() {
    python -mvenv ~/.virtualenvs/$1
    . $HOME/.virtualenvs/$1/bin/activate
}
alias workon=__workon
alias mkvirtualenv=__mkvirtualenv

# Enable asdf (virtual environments)
# This conflicts with pyenv, which i tend to prefer.
# As a result this should be enabled per-project via direnv
# echo ". /opt/homebrew/opt/asdf/libexec/asdf.sh" >> .envrc
#if [ -f /opt/homebrew/opt/asdf/libexec/asdf.sh ]; then
#    # brew
#    . /opt/homebrew/opt/asdf/libexec/asdf.sh
#fi
#if [ -f "$HOME/.asdf/asdf.sh" ]; then
#    . "$HOME/.asdf/asdf.sh"
#    . "$HOME/.asdf/completions/asdf.bash"
#fi
#######

# Enable system bash completions

## Debian derivative
if [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
fi

## Void
if [ -d /usr/share/bash-completion/completions ]; then
    for c in $(ls -1 /usr/share/bash-completion/completions/);
    do
        # grub's completion uses a deprecated `have`
        [ "$c" == "grub" ] && continue
        . /usr/share/bash-completion/completions/$c
    done
fi

## FreeBSD
[[ -n $PS1 && -f /usr/local/share/bash-completion/bash_completion.sh ]] && \
	source /usr/local/share/bash-completion/bash_completion.sh

if [[ $OS_NAME == "FreeBSD" || $OS_NAME == "OpenBSD" ]]; then
    export XDG_RUNTIME_DIR=/var/run/user/`id -u`
fi
#######

# FZF

## Void
if [ -f /usr/share/fzf/completion.bash ]; then
    . /usr/share/fzf/completion.bash
    . /usr/share/fzf/key-bindings.bash
fi
## Debian
if [ -f /usr/share/doc/fzf/examples/completion.bash ]; then
    # For apt install fzf
    . /usr/share/doc/fzf/examples/completion.bash
    . /usr/share/doc/fzf/examples/key-bindings.bash
fi

## OS X/homebrew
if [ -f /opt/homebrew/opt/fzf/shell/completion.bash ]; then
    . /opt/homebrew/opt/fzf/shell/completion.bash
    . /opt/homebrew/opt/fzf/shell/key-bindings.bash
fi

## OpenBSD
if [ -f /usr/local/share/fzf/bash/key-bindings.bash ]; then
    . /usr/local/share/fzf/bash/key-bindings.bash
    . /usr/local/share/fzf/bash/completion.bash
fi

## TCL/TK via homebrew
## OS X packages an outdated and deprecated version that doesn't really
## work.
if [ -d /opt/homebrew/opt/tcl-tk/bin ]; then
    PATH=/opt/homebrew/opt/tcl-tk/bin:$PATH
fi

#######

#TERM="xterm-256color"

# direnv's use_nix will overwrite TMPDIR so it needs to be hard coded to /tmp/
#EMACS_SERVER_SOCKET="/tmp/emacs$(id -u)/server"
#EMACS_SERVER_SOCKET="${TMPDIR:-/tmp}/emacs$(id -u)/server"
#EDITOR="emacsclient -s ${EMACS_SERVER_SOCKET}"

export EDITOR='emacsclient -nw'
alias e="${EDITOR}"

# History settings
#export HISTTIMEFORMAT="[%F %T] "
export HISTSIZE=99999          # Store unlimited entries. Default: 500
export HISTFILESIZE=999999999  # Unlimited file size
# Store history immediately
## history -r rereads
export PROMPT_COMMAND="history -a;history -r; ${PROMPT_COMMAND}"
#export PROMPT_COMMAND="history -a; ${PROMPT_COMMAND}"
export HISTCONTROL="ignoredups"
export HISTIGNORE="ls:cd"
shopt -s histappend     # append entries rather than overwrite
shopt -s cmdhist        # Store multi-line commands as a single line

# Aliases
#alias ls='ls --color'
#alias fixfileperm='find /music -type f -exec chmod 0644 {} \;'
#alias cleanremotebranches='git branch --merged | grep -v "\*" | xargs -n 1 git branch -d; git branch -r --merged master | grep -iv "master" | sed "s/origin\///" | xargs -n 1 git push --delete origin'
alias ducks='du -cks * |sort -rn |head -11'
alias define='sdcv'
#alias cleanstale="git clean -fd -e'!__pycache__' -e'!*.py[cod]'"
#alias dry-cleanstale="git clean -fdn -e'!__pycache__' -e'!*.py[cod]'"

# Enable direnv (https://github.com/direnv/direnv/)
DIRENV=`which direnv 2> /dev/null`
if [ -x "$DIRENV" ]; then
    eval "$(direnv hook bash)"
fi
show_virtual_env() {
  if [[ -n "$VIRTUAL_ENV" && -n "$DIRENV_DIR" ]]; then
    echo "($(basename $VIRTUAL_ENV))"
  fi
}
export -f show_virtual_env
PS1='$(show_virtual_env)'$PS1

# Git Related
function delete-branches() {
    # Interactive branch deleter
    git branch |
	grep --invert-match '\*' |
	cut -c 3- |
	fzf --multi --preview="git log {} --" |
	xargs git branch --delete --force
}

XCODE_SELECT=`which xcode-select 2> /dev/null`
if [[ -x $XCODE_SELECT ]]; then
    OSX_GIT_COMPLETION=`xcode-select -p`/usr/share/git-core/git-completion.bash
    if [[ -f $OSX_GIT_COMPLETION ]]; then
        source $OSX_GIT_COMPLETION
    fi
    OSX_GIT_PROMPT=`xcode-select -p`/usr/share/git-core/git-prompt.sh
    if [[ -f $OSX_GIT_PROMPT ]]; then
        source $OSX_GIT_PROMPT
    fi
fi

# The Gemini earbuds don't sync the volume. This turns up the hardware volume control
alias geminiup="dbus-send --print-reply --system --dest=org.bluez /org/bluez/hci0/dev_7C_C4_EF_CC_45_43 org.bluez.MediaControl1.VolumeUp"
alias geminidown="dbus-send --print-reply --system --dest=org.bluez /org/bluez/hci0/dev_7C_C4_EF_CC_45_43 org.bluez.MediaControl1.VolumeDown"

# Enable firefox touchscreen scrolling
# export MOZ_USE_XINPUT2=1
export MOZ_ENABLE_WAYLAND=1
export XCURSOR_SIZE=32

# GPG ssh key
#export GPG_TTY=$(tty)
export SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket)"

# Enable warpdir (https://rc4.net/wd-rs/)
WARPDIR=`which warpdir 2> /dev/null`
if [[ -x $WARPDIR ]]; then
    eval "$(warpdir hook bash)"
fi

# Enable terraform completions
TERRAFORM=`which terraform 2> /dev/null`
if [[ -x $TERRAFORM ]]; then
    complete -C $TERRAFORM terraform
fi

# texinfo is keg-only, which means it was not symlinked into /opt/homebrew,
# because macOS already provides this software and installing another version
# in parallel can cause all kinds of trouble.
if [ -d /opt/homebrew/opt/texinfo/bin ]; then
    export PATH="/opt/homebrew/opt/texinfo/bin:$PATH"
fi

if [ -d "$HOME/.nvm" ] && [ -s $HOME/.nvm/nvm.sh ]; then
    export NVM_DIR="${HOME}/.nvm"
    . "$NVM_DIR/nvm.sh"
    if [ -s "$NVM_DIR/bash_completion" ]; then
       . "$NVM_DIR/bash_completion"
    fi
fi

# If __git_ps1 is enabled, set that up.
if [[ $(type -t __git_ps1) == function ]]; then
    GIT_PS1_SHOWDIRTYSTATE=1  # Show unstaged and staged indicators
    GIT_PS1_SHOWUNTRACKEDFILES=1  # show % for untracked files
    # GIT_PS1_SHOWUPSTREAM=auto  # show +/- changes with upstream
    PS1=$PS1'$(__git_ps1 " (%s)")'

    # Alternatively, for a slightly faster prompt, __git_ps1 can  be
    # used for PROMPT_COMMAND in Bash with two parameters, <pre> and
    # <post>, which are strings you would put in $PS1 before and after
    # the status string generated by the git-prompt machinery.
    # DISABLED because this doesn't work with $(show_virtualenv)
    #export PROMPT_COMMAND="__git_ps1 '${PS1}' '${END_PS1}'; ${PROMPT_COMMAND}"
fi

# Helper Functions
at-finit() {
    local OPTIND name adminuser password
    while getopts "n:u:" opt; do
        case $opt in
            n)
                name=$OPTARG
                ;;
            u)
                adminuser=$OPTARG
                ;;
            \?)
                # quit on arg error
                return 1
                ;;
        esac
    done

    if [ -z "$name" ]; then
        echo "-n required"
        return 1
    fi
    if [ -z "$adminuser" ]; then
        echo "-u required"
        return 1
    fi

    repopath="$HOME/Code/Museum/$name.fossil"
    printf "path is: $repopath\n"

    stty -echo
    printf "Set admin password: "
    read password
    stty echo
    printf "\n"

    fossil init --template $HOME/Sync/Files/template-repo-v1.fossil --admin-user "$adminuser" "$repopath" > /dev/null
    fossil user -R $repopath password $adminuser $password

    chmod 0664 $repopath
    rsync --perms $repopath jason@depot.waldorf._.antitech.org:/var/www/htdocs/depot.antitech.org
    chmod 0644 $repopath

    urluser=$(echo $adminuser | jq "@uri" -jRr)
    urlpasswd=$(echo $password | jq "@uri" -jRr)
    echo "Defining remote..."
    fossil remote-url -R $repopath https://$urluser:$urlpasswd@depot.antitech.org/$name/

    printf "\nSuccess. View your public repository at https://depot.antitech.org/${name}/\n"
}

# Close off the PS1 with the $
PS1=${PS1}${END_PS1}