Skip to content

File tree

1 file changed

+127
-0
lines changed

1 file changed

+127
-0
lines changed

.repronim.bashrc

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
set -o noclobber # do not overwrite existing files
2+
set -o emacs # use the emacs shortcuts
3+
4+
# function to help remind users about the shortcuts
5+
repronim_bashrc_help() {
6+
LINE="Commandline/Cursor Editing Shortcuts::
7+
Ctrl-a: Go to the beginning of the line you are currently typing on
8+
Ctrl-e: Go to the end of the line you are currently typing on
9+
Ctrl-u: Remove text on the line before the cursor position
10+
Ctrl-h: Remove preceding symbol (same as backspace)
11+
Ctrl-w: Delete the word before the cursor
12+
Ctrl-k: Remove text on the line after the cursor position
13+
Ctrl-t: Swap the last two characters before the cursor
14+
Alt-t: Swap the last two words before the cursor
15+
Alt-f: Move cursor forward one word on the current line
16+
Alt-b: Move cursor backward one word on the current line
17+
Tab: Auto-complete files, folders, and command names
18+
Ctrl-x Ctrl-e OR Alt-e in zsh: Edit command line text in the editor (as defined by VISUAL environment variable)"
19+
20+
CONTROL="Job Control Shortcuts::
21+
Ctrl-c: Kill currently running process
22+
Ctrl-d: Exit current shell
23+
Ctrl-z: Suspend currently running process. fg restores it, and bg places it into background execution"
24+
25+
HISTORY="History Shortcuts::
26+
Ctrl-p: Previous line in the history
27+
Ctrl-n: Next line in the history
28+
Ctrl-r: Bring up next match backwards in shell history"
29+
30+
if [ $# -lt 1 ]; then
31+
echo -e "${LINE}\n\n${CONTROL}\n\n${HISTORY}"
32+
return 0
33+
fi
34+
35+
while [ $# -ge 1 ]; do
36+
case "$1"
37+
in
38+
n)
39+
echo -e "$LINE\n"
40+
shift;;
41+
line)
42+
echo -e "$LINE\n"
43+
shift;;
44+
c)
45+
echo -e "$CONTROL\n"
46+
shift;;
47+
control)
48+
echo -e "$CONTROL\n"
49+
shift;;
50+
h)
51+
echo -e "$HISTORY\n"
52+
shift;;
53+
history)
54+
echo -e "$HISTORY\n"
55+
shift;;
56+
-h)
57+
echo "Options are: n, line, c, control, h, history or blank"
58+
echo "Example1: print_shortcuts n c h"
59+
echo "Example2: print_shortcuts"
60+
return 0
61+
;;
62+
--help)
63+
echo "Options are: n, line, c, control, h, history or blank"
64+
echo "Example1: print_shortcuts n c h"
65+
echo "Example2: print_shortcuts"
66+
return 0
67+
;;
68+
*)
69+
echo "Option $1 not recognized use (n, line, c, control, h, history or blank)"
70+
echo "type print_shortcuts -h for help"
71+
echo "Example1: print_shortcuts n c h"
72+
echo "Example2: print_shortcuts"
73+
return 1
74+
;;
75+
esac
76+
done
77+
}
78+
79+
80+
# create an eternal bash history file
81+
# https://debian-administration.org/article/543/Bash_eternal_history
82+
83+
bhf="${HOME}/.bash_eternal_history"
84+
if [ ! -f "${bhf}" ]; then
85+
touch "${bhf}"
86+
fi
87+
88+
if [ "$(stat -c %a "${bhf}")" != "600" ]; then
89+
chmod 600 "${bhf}"
90+
fi
91+
92+
# NOTE: I changed ${PROMPT_COMMAND:...} to ${PROMPT_COMMAND%%;:...}
93+
# to account for trailing semicolons existing in the commmand (like if you've installed pyenv)
94+
# see: https://github.com/pyenv/pyenv-virtualenv/issues/247
95+
export HISTTIMEFORMAT="%s "
96+
97+
PROMPT_COMMAND="${PROMPT_COMMAND%%;:+$PROMPT_COMMAND ; }"'echo $$ $USER "$(history 1)" >> ${bhf}'
98+
99+
# make a terminal prompt that shows the full path: http://ezprompt.net/
100+
export PS1="\[\e[33m\]\u\[\e[m\]:\[\e[35m\]\s\[\e[m\]\[\e[37m\]:\[\e[m\]\[\e[36m\]\w\[\e[m\]\\$ "
101+
102+
if [ ! -z "$PS1" ]; then
103+
# include a marker into PS1 that we are in the singularity image
104+
# Since we are using git-annex forcd images, SINGULARITY_NAME would
105+
# carry the dereferenced filename - git-annex key which is not
106+
# that useful to see, so we just add [SING] marker
107+
if ! echo "$PS1" | grep -q SINGULARITY_NAME && [ ! -z "$SINGULARITY_NAME" ]; then
108+
# proposed in https://github.com/datalad/datalad-container/pull/84
109+
if [ ! -z "${DATALAD_CONTAINER_NAME:-}" ]; then
110+
_name="$DATALAD_CONTAINER_NAME"
111+
elif echo "$SINGULARITY_NAME" | grep -q '^MD5E-'; then
112+
# singularity < 3. dereferences symlinks -
113+
# annexed keys are too long/useless in this context, we shorten
114+
_name=$(echo "${SINGULARITY_NAME##*--}" | cut -c 1-8)...
115+
else
116+
_name="$SINGULARITY_NAME"
117+
fi
118+
# strip our possible suffix
119+
_name="$(echo "$_name" | sed -e 's,.sing$,,g')"
120+
export PS1="singularity:$_name > $PS1"
121+
fi
122+
fi
123+
124+
# USER variable might not be defined in sanitized environment
125+
# but could be needed by some tools, e.g. FSL. See
126+
# https://github.com/kaczmarj/neurodocker/pull/270
127+
export USER="${USER:=$(whoami)}"

0 commit comments

Comments
 (0)