-
Notifications
You must be signed in to change notification settings - Fork 0
/
.shellrc
88 lines (74 loc) · 3 KB
/
.shellrc
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
#!/bin/sh
#
# Damien Dart's cross-shell configuration file for interactive shells.
#
# This file was written by Damien Dart, <[email protected]>. This is
# free and unencumbered software released into the public domain. For
# more information, please refer to the accompanying "UNLICENCE file.
# Given a new-line-separated list of filenames via STDIN, source
# the first file that exists. The first parameter is an identifier for
# the list of filenames provided and is used in error messages.
shellrc__source_one ()
{
# shellcheck disable=2034
IPS="\n"
while read -r ITEM; do
if [ -f "$ITEM" ]; then
# shellcheck disable=SC1090
. "$ITEM"
return
fi
done
echo "[✘] $0: Unable to source anything for \"$1\"" 1>&2
}
shellrc__prompt_command ()
{
LAST_COMMAND_EXIT_STATUS="$?"
# The following super-minimalist interactive shell prompt is based on
# <https://twitter.com/thingskatedid/status/1316081075043463170>,
# <https://twitter.com/thingskatedid/status/1316081732467081217>, and
# <https://unix.stackexchange.com/questions/62173/exit-status-of-148-upon-ctrlz>.
if [ $LAST_COMMAND_EXIT_STATUS = "0" ] || [ $LAST_COMMAND_EXIT_STATUS = "148" ]; then
PS1=":; "
else
PS1="\[\e[1;31m\]:; \[\e[0m\]"
fi
# "pathshorten" is a standalone implementation of Vim's "pathshorten"
# function written in Go. For more information, see
# <https://github.com/damiendart/pathshorten>.
if command -v pathshorten 1>/dev/null 2>&1; then
# shellcheck disable=SC2089
FZF_CTRL_T_OPTS="${FZF_CTRL_T_OPTS_BASE} --prompt='$(pathshorten -n)/'"
fi
}
PROMPT_COMMAND='shellrc__prompt_command'
# Improve support for coloured terminal output and special key presses
# when using python-build-standalone Python distributions. For more
# information, see <https://gregoryszorc.com/docs/python-build-standalone/main/quirks.html#backspace-key-doesn-t-work-in-python-repl>.
export TERMINFO_DIRS="/etc/terminfo:/lib/terminfo:/usr/share/terminfo"
if type 'fzf' 1>/dev/null 2>&1; then
export FZF_CTRL_R_OPTS="--prompt=';; '"
# shellcheck disable=SC2089,SC2090
export FZF_CTRL_T_OPTS='--exit-0 --preview="cat {} 2>/dev/null | head -200" --select-1'
export FZF_CTRL_T_OPTS_BASE="${FZF_CTRL_T_OPTS}"
export FZF_DEFAULT_OPTS='--border --info=inline-right --layout=reverse'
if type 'rg' 1>/dev/null 2>&1; then
export FZF_CTRL_T_COMMAND='rg --files --hidden'
export FZF_DEFAULT_COMMAND="$FZF_CTRL_T_COMMAND"
fi
if type 'tree' 1>/dev/null 2>&1; then
export FZF_ALT_C_OPTS="--preview='tree {} | head -200' --prompt=';; cd '"
# shellcheck disable=SC2090
export FZF_CTRL_T_OPTS='--exit-0 --preview="(cat {} || tree -C {}) 2>/dev/null | head -200" --select-1'
# shellcheck disable=SC2090
export FZF_CTRL_T_OPTS_BASE="${FZF_CTRL_T_OPTS}"
fi
fi
# Improve the viewing of some non-text input in "less" with "lesspipe".
if type 'lesspipe' 1>/dev/null 2>&1; then
eval "$(SHELL=/bin/sh lesspipe)"
fi
if [ -f ~/.machine.shellrc ]; then
# shellcheck disable=SC1090
. ~/.machine.shellrc
fi