diff options
Diffstat (limited to 'bash')
-rw-r--r-- | bash/aliases.bash | 3 | ||||
-rw-r--r-- | bash/bashrc | 1 | ||||
-rw-r--r-- | bash/functions.bash | 43 | ||||
-rw-r--r-- | bash/prompt.bash | 20 | ||||
-rw-r--r-- | bash/vterm-emacs.bash | 23 |
5 files changed, 67 insertions, 23 deletions
diff --git a/bash/aliases.bash b/bash/aliases.bash index 59e76d3..7875574 100644 --- a/bash/aliases.bash +++ b/bash/aliases.bash | |||
@@ -24,3 +24,6 @@ alias lake='make PREFIX=~/usr' | |||
24 | 24 | ||
25 | # bash meta | 25 | # bash meta |
26 | alias rebash='source ~/.bash_profile' | 26 | alias rebash='source ~/.bash_profile' |
27 | |||
28 | # Debugging | ||
29 | alias emacs_goddamnit='pushd ~/.emacs.d;emacs --debug-init;popd' | ||
diff --git a/bash/bashrc b/bash/bashrc index e167fee..f9f17e7 100644 --- a/bash/bashrc +++ b/bash/bashrc | |||
@@ -10,6 +10,7 @@ BASH_SOURCE_FIRST=( | |||
10 | 10 | ||
11 | BASH_SOURCE_LAST=( | 11 | BASH_SOURCE_LAST=( |
12 | blesh | 12 | blesh |
13 | vterm-emacs | ||
13 | ) | 14 | ) |
14 | 15 | ||
15 | for f in "${BASH_SOURCE_FIRST[@]}"; do | 16 | for f in "${BASH_SOURCE_FIRST[@]}"; do |
diff --git a/bash/functions.bash b/bash/functions.bash index 5e99a82..98872f2 100644 --- a/bash/functions.bash +++ b/bash/functions.bash | |||
@@ -1,8 +1,8 @@ | |||
1 | # Functions | 1 | # Functions |
2 | 2 | ||
3 | memq() { # memq ITEM ARRAY | 3 | memq() { # memq ITEM ARRAY |
4 | # Test whether an ITEM is a member of ARRAY. | 4 | ## Test whether an ITEM is a member of ARRAY. |
5 | # Pass ARRAY as ${ARRAY[@]}. | 5 | ## Pass ARRAY as ${ARRAY[@]}. |
6 | local e needle="$1"; shift | 6 | local e needle="$1"; shift |
7 | for e; do | 7 | for e; do |
8 | [[ "$e" == "$needle" ]] && { | 8 | [[ "$e" == "$needle" ]] && { |
@@ -12,15 +12,34 @@ memq() { # memq ITEM ARRAY | |||
12 | return 1 | 12 | return 1 |
13 | } | 13 | } |
14 | 14 | ||
15 | rebashrc() { # rebashrc | ||
16 | ## Reload ~/.bashrc | ||
17 | printf "Loading ~/.bashrc..." >&2 | ||
18 | if source "$HOME/.bashrc"; then | ||
19 | echo "OK." >&2 | ||
20 | else | ||
21 | echo "ERROR!" >&2 | ||
22 | fi | ||
23 | } | ||
24 | |||
25 | first_which() { # first_which COMMAND... | ||
26 | ## Return the fully-qualified path of the first COMMAND found in $PATH. | ||
27 | while :; do | ||
28 | command -v "$1" && break | ||
29 | [ -z "$1" ] && return 1 | ||
30 | shift | ||
31 | done | ||
32 | } | ||
33 | |||
15 | please() { # please [COMMAND...] | 34 | please() { # please [COMMAND...] |
16 | # if run without arguments, run the last command with 'sudo' (aka sudo !!) | 35 | # if run without arguments, run the last command with 'sudo' (aka sudo !!) |
17 | # if run WITH arguments, alias as sudo | 36 | # if run WITH arguments, alias as sudo |
18 | history -d -1 | 37 | history -d -1 |
19 | if [ -z "$1" ]; then | 38 | if [ -z "$1" ]; then |
20 | #set -- $(HISTTIMEFORMAT=$'\t' history 2 | sed 's/^.*\t//;q') | 39 | #set -- $(HISTTIMEFORMAT=$'\t' history 2 | sed 's/^.*\t//;q') |
21 | set -- $(fc -lnr | sed 1q) | 40 | set -- $(fc -lnr | sed 1q) |
22 | fi | 41 | fi |
23 | echo >&2 sudo "$@" | 42 | echo >&2 sudo "$@" |
24 | history -s sudo "$@" | 43 | history -s sudo "$@" |
25 | "${DEBUG:-false}" || sudo "$@" | 44 | "${DEBUG:-false}" || sudo "$@" |
26 | } | 45 | } |
diff --git a/bash/prompt.bash b/bash/prompt.bash index 02d9c98..f1bdd69 100644 --- a/bash/prompt.bash +++ b/bash/prompt.bash | |||
@@ -4,7 +4,7 @@ PS1= | |||
4 | 4 | ||
5 | # user, host, and cwd | 5 | # user, host, and cwd |
6 | PROMPT_DIRTRIM=3 # how many dirs above current to print (rest are '...') | 6 | PROMPT_DIRTRIM=3 # how many dirs above current to print (rest are '...') |
7 | PS1+='\[\e[34m\]# \u@\h \w' | 7 | PS1+='\[\e[0;46m\]\u@\h \w' |
8 | 8 | ||
9 | # git bit | 9 | # git bit |
10 | # see https://unix.stackexchange.com/questions/278206 | 10 | # see https://unix.stackexchange.com/questions/278206 |
@@ -16,13 +16,11 @@ possible_git_prompt_locations=( | |||
16 | ) | 16 | ) |
17 | 17 | ||
18 | for file in "${possible_git_prompt_locations[@]}"; do | 18 | for file in "${possible_git_prompt_locations[@]}"; do |
19 | if [[ -f "$file" ]]; then | 19 | if [[ -f "$file" ]]; then |
20 | source "$file" && | 20 | source "$file" && |
21 | PS1+='\[\e[35m\]$(__git_ps1)' | 21 | PS1+='\[\e[35m\]$(__git_ps1)' |
22 | break | 22 | break |
23 | else | 23 | fi |
24 | true | ||
25 | fi | ||
26 | done | 24 | done |
27 | 25 | ||
28 | # newline | 26 | # newline |
@@ -30,9 +28,9 @@ PS1+='\[\e[0m\]\n' | |||
30 | 28 | ||
31 | # exit code (only if error) | 29 | # exit code (only if error) |
32 | __prompt_exit_code() { | 30 | __prompt_exit_code() { |
33 | local ec=$? | 31 | local ec=$? |
34 | (( $ec > 0 )) && | 32 | (( $ec > 0 )) && |
35 | printf "$ec" | 33 | printf "$ec" |
36 | } | 34 | } |
37 | PS1+='\[\e[31m\]$(__prompt_exit_code)\[\e[0m\]' | 35 | PS1+='\[\e[31m\]$(__prompt_exit_code)\[\e[0m\]' |
38 | 36 | ||
diff --git a/bash/vterm-emacs.bash b/bash/vterm-emacs.bash new file mode 100644 index 0000000..88d3e09 --- /dev/null +++ b/bash/vterm-emacs.bash | |||
@@ -0,0 +1,23 @@ | |||
1 | # shell-side configuration for Emacs vterm module | ||
2 | # https://github.com/akermu/emacs-libvterm#shell-side-configuration | ||
3 | # Make sure this is the last file loaded by ~/.bashrc! | ||
4 | |||
5 | # Load the requisite code from the vterm install directory | ||
6 | if [[ "$INSIDE_EMACS" = 'vterm' ]] \ | ||
7 | && [[ -n ${EMACS_VTERM_PATH} ]] \ | ||
8 | && [[ -f ${EMACS_VTERM_PATH}/etc/emacs-vterm-bash.sh ]]; then | ||
9 | source ${EMACS_VTERM_PATH}/etc/emacs-vterm-bash.sh | ||
10 | fi | ||
11 | |||
12 | # Extra commands for `vterm-eval-cmds' | ||
13 | |||
14 | find_file() { | ||
15 | vterm_cmd find-file "$(realpath "${@:-.}")" | ||
16 | } | ||
17 | |||
18 | say() { | ||
19 | vterm_cmd message "%s" "$*" | ||
20 | } | ||
21 | |||
22 | |||
23 | |||