From 7dee9ca5b36f5a3bd78e7245bb014398d8e17e15 Mon Sep 17 00:00:00 2001 From: James Kent Date: Sat, 9 Mar 2019 10:14:49 -0600 Subject: [PATCH 1/7] add opinionated .bashrc --- files/repronim.bashrc | 81 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 files/repronim.bashrc diff --git a/files/repronim.bashrc b/files/repronim.bashrc new file mode 100644 index 0000000..c501212 --- /dev/null +++ b/files/repronim.bashrc @@ -0,0 +1,81 @@ + +set -o noclobber +set -o emacs + +print_shortcuts() { +LINE="Commandline/Cursor Editing Shortcuts:: +Ctrl-a: Go to the beginning of the line you are currently typing on +Ctrl-e: Go to the end of the line you are currently typing on +Ctrl-u: Remove text on the line before the cursor position +Ctrl-h: Remove preceding symbol (same as backspace) +Ctrl-w: Delete the word before the cursor +Ctrl-k: Remove text on the line after the cursor position +Ctrl-t: Swap the last two characters before the cursor +Alt-t: Swap the last two words before the cursor +Alt-f: Move cursor forward one word on the current line +Alt-b: Move cursor backward one word on the current line +Tab: Auto-complete files, folders, and command names +Ctrl-x OR Ctrl-e OR Alt-e in zsh: Edit command line text in the editor (as defined by VISUAL environment variable)" +CONTROL="Job Control Shortcuts:: +Ctrl-c: Kill currently running process +Ctrl-d: Exit current shell +Ctrl-z: Suspend currently running process. fg restores it, and bg places it into background execution" +HISTORY="History Shortcuts:: +Ctrl-p: Previous line in the history +Ctrl-n: Next line in the history +Ctrl-r: Bring up next match backwards in shell history" + if [ $# -lt 1 ]; then + echo -e "${LINE}\n\n${CONTROL}\n\n${HISTORY}" + return 0 + fi + + while [ $# -ge 1 ]; do + case "$1" + in + n) + echo -e "$LINE\n" + shift;; + line) + echo -e "$LINE\n" + shift;; + c) + echo -e "$CONTROL\n" + shift;; + control) + echo -e "$CONTROL\n" + shift;; + h) + echo -e "$HISTORY\n" + shift;; + history) + echo -e "$HISTORY\n" + shift;; + -h) + echo "Options are: n, line, c, control, h, history or nothing at all" + return 0 + ;; + *) + echo "Option $1 not recognized use (n, line, c, control, h, history or nothing at all)" + return 1 + ;; + esac + done +} + + +# https://debian-administration.org/article/543/Bash_eternal_history + +bhf="${HOME}/.bash_eternal_history" +if [ ! -f "${bhf}" ]; then + touch "${bhf}" +fi + +if [ "$(stat -c %a "${bhf}")" != "600" ]; then + chmod 600 "${bhf}" +fi + +export HISTTIMEFORMAT="%s " +PROMPT_COMMAND="${PROMPT_COMMAND%%;:+$PROMPT_COMMAND ; }"'echo $$ $USER "$(history 1)" >> ${bhf}' + +# make a prompt: http://ezprompt.net/ +export PS1="\[\e[33m\]\u\[\e[m\]:\[\e[35m\]\s\[\e[m\]\[\e[37m\]:\[\e[m\]\[\e[36m\]\w\[\e[m\]\\$ " \ No newline at end of file From a160893634fdeb603bcfb645249c286b1087cb24 Mon Sep 17 00:00:00 2001 From: James Kent Date: Sat, 9 Mar 2019 10:55:17 -0600 Subject: [PATCH 2/7] add in reference to .repronim.bashrc --- _episodes/01-shell-basics.md | 9 +++++++++ files/repronim.bashrc => code/.repronim.bashrc | 0 2 files changed, 9 insertions(+) rename files/repronim.bashrc => code/.repronim.bashrc (100%) diff --git a/_episodes/01-shell-basics.md b/_episodes/01-shell-basics.md index 1d48fea..8fb74e8 100644 --- a/_episodes/01-shell-basics.md +++ b/_episodes/01-shell-basics.md @@ -545,6 +545,15 @@ and so on. > popular command {: .challenge} +> ## An opinionated `.repronim.bashrc` +> +> If you would like to see an example of a `.bashrc` file that makes reproducible +> practices the "default" option, checkout [.repronim.bashrc](({{ page.root }}/code/.repronim.bashrc)). +> You can either `source` this file in your existing `.bashrc` file +> (e.g. you can copy this file to your home directory and add `source ~/.repronim.bashrc` +> to your original `.bashrc` file) +> or you can copy/paste useful lines from this file to your `.bashrc`. +{: .callout} ## Hints for correct/robust scripting in shell diff --git a/files/repronim.bashrc b/code/.repronim.bashrc similarity index 100% rename from files/repronim.bashrc rename to code/.repronim.bashrc From f85d93ab1ccf3899a7960d1e22bce93c62afd45c Mon Sep 17 00:00:00 2001 From: James Kent Date: Sat, 9 Mar 2019 10:56:09 -0600 Subject: [PATCH 3/7] rm .gitkeep in code folder --- code/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 code/.gitkeep diff --git a/code/.gitkeep b/code/.gitkeep deleted file mode 100644 index e69de29..0000000 From c70b1986fef8d85d217f8dc3c989842f2d5835f9 Mon Sep 17 00:00:00 2001 From: James Kent Date: Sat, 9 Mar 2019 11:04:49 -0600 Subject: [PATCH 4/7] add comments and make function help clearer --- code/.repronim.bashrc | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/code/.repronim.bashrc b/code/.repronim.bashrc index c501212..e1fe977 100644 --- a/code/.repronim.bashrc +++ b/code/.repronim.bashrc @@ -1,7 +1,7 @@ +set -o noclobber # do not overwrite existing files +set -o emacs # use the emacs shortcuts -set -o noclobber -set -o emacs - +# function to help remind users about the shortcuts print_shortcuts() { LINE="Commandline/Cursor Editing Shortcuts:: Ctrl-a: Go to the beginning of the line you are currently typing on @@ -51,11 +51,22 @@ Ctrl-r: Bring up next match backwards in shell history" echo -e "$HISTORY\n" shift;; -h) - echo "Options are: n, line, c, control, h, history or nothing at all" + echo "Options are: n, line, c, control, h, history or blank" + echo "Example1: print_shortcuts n c h" + echo "Example2: print_shortcuts" + return 0 + ;; + --help) + echo "Options are: n, line, c, control, h, history or blank" + echo "Example1: print_shortcuts n c h" + echo "Example2: print_shortcuts" return 0 ;; *) - echo "Option $1 not recognized use (n, line, c, control, h, history or nothing at all)" + echo "Option $1 not recognized use (n, line, c, control, h, history or blank)" + echo "type print_shortcuts -h for help" + echo "Example1: print_shortcuts n c h" + echo "Example2: print_shortcuts" return 1 ;; esac @@ -63,6 +74,7 @@ Ctrl-r: Bring up next match backwards in shell history" } +# create an eternal bash history file # https://debian-administration.org/article/543/Bash_eternal_history bhf="${HOME}/.bash_eternal_history" @@ -74,8 +86,11 @@ if [ "$(stat -c %a "${bhf}")" != "600" ]; then chmod 600 "${bhf}" fi +# NOTE: I changed ${PROMPT_COMMAND:...} to ${PROMPT_COMMAND%%;:...} +# to account for trailing semicolons existing in the commmand (like if you've installed pyenv) +# see: https://github.com/pyenv/pyenv-virtualenv/issues/247 export HISTTIMEFORMAT="%s " PROMPT_COMMAND="${PROMPT_COMMAND%%;:+$PROMPT_COMMAND ; }"'echo $$ $USER "$(history 1)" >> ${bhf}' -# make a prompt: http://ezprompt.net/ +# make a terminal prompt that shows the full path: http://ezprompt.net/ export PS1="\[\e[33m\]\u\[\e[m\]:\[\e[35m\]\s\[\e[m\]\[\e[37m\]:\[\e[m\]\[\e[36m\]\w\[\e[m\]\\$ " \ No newline at end of file From 5a2da84216718a377b1aba3c4b7899abffeecd67 Mon Sep 17 00:00:00 2001 From: James Kent Date: Sat, 9 Mar 2019 11:05:27 -0600 Subject: [PATCH 5/7] formatting --- code/.repronim.bashrc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/code/.repronim.bashrc b/code/.repronim.bashrc index e1fe977..bd0629b 100644 --- a/code/.repronim.bashrc +++ b/code/.repronim.bashrc @@ -16,14 +16,17 @@ Alt-f: Move cursor forward one word on the current line Alt-b: Move cursor backward one word on the current line Tab: Auto-complete files, folders, and command names Ctrl-x OR Ctrl-e OR Alt-e in zsh: Edit command line text in the editor (as defined by VISUAL environment variable)" + CONTROL="Job Control Shortcuts:: Ctrl-c: Kill currently running process Ctrl-d: Exit current shell Ctrl-z: Suspend currently running process. fg restores it, and bg places it into background execution" + HISTORY="History Shortcuts:: Ctrl-p: Previous line in the history Ctrl-n: Next line in the history Ctrl-r: Bring up next match backwards in shell history" + if [ $# -lt 1 ]; then echo -e "${LINE}\n\n${CONTROL}\n\n${HISTORY}" return 0 From 3b059b9b99d03034dcf2d0722328bf0fb30831ba Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Tue, 30 Apr 2019 14:30:17 -0400 Subject: [PATCH 6/7] BF: fixed up shortcut for entering cmdline editing mode in emacs - should not be OR but both --- code/.repronim.bashrc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/.repronim.bashrc b/code/.repronim.bashrc index bd0629b..6c65a09 100644 --- a/code/.repronim.bashrc +++ b/code/.repronim.bashrc @@ -15,7 +15,7 @@ Alt-t: Swap the last two words before the cursor Alt-f: Move cursor forward one word on the current line Alt-b: Move cursor backward one word on the current line Tab: Auto-complete files, folders, and command names -Ctrl-x OR Ctrl-e OR Alt-e in zsh: Edit command line text in the editor (as defined by VISUAL environment variable)" +Ctrl-x Ctrl-e OR Alt-e in zsh: Edit command line text in the editor (as defined by VISUAL environment variable)" CONTROL="Job Control Shortcuts:: Ctrl-c: Kill currently running process @@ -96,4 +96,4 @@ export HISTTIMEFORMAT="%s " PROMPT_COMMAND="${PROMPT_COMMAND%%;:+$PROMPT_COMMAND ; }"'echo $$ $USER "$(history 1)" >> ${bhf}' # make a terminal prompt that shows the full path: http://ezprompt.net/ -export PS1="\[\e[33m\]\u\[\e[m\]:\[\e[35m\]\s\[\e[m\]\[\e[37m\]:\[\e[m\]\[\e[36m\]\w\[\e[m\]\\$ " \ No newline at end of file +export PS1="\[\e[33m\]\u\[\e[m\]:\[\e[35m\]\s\[\e[m\]\[\e[37m\]:\[\e[m\]\[\e[36m\]\w\[\e[m\]\\$ " From 979215708f2f22a2c9d43ffca865455c3b41d1bb Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Tue, 30 Apr 2019 14:37:48 -0400 Subject: [PATCH 7/7] ENH: indent shortcuts items by a single space --- code/.repronim.bashrc | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/code/.repronim.bashrc b/code/.repronim.bashrc index 6c65a09..92aa179 100644 --- a/code/.repronim.bashrc +++ b/code/.repronim.bashrc @@ -4,28 +4,28 @@ set -o emacs # use the emacs shortcuts # function to help remind users about the shortcuts print_shortcuts() { LINE="Commandline/Cursor Editing Shortcuts:: -Ctrl-a: Go to the beginning of the line you are currently typing on -Ctrl-e: Go to the end of the line you are currently typing on -Ctrl-u: Remove text on the line before the cursor position -Ctrl-h: Remove preceding symbol (same as backspace) -Ctrl-w: Delete the word before the cursor -Ctrl-k: Remove text on the line after the cursor position -Ctrl-t: Swap the last two characters before the cursor -Alt-t: Swap the last two words before the cursor -Alt-f: Move cursor forward one word on the current line -Alt-b: Move cursor backward one word on the current line -Tab: Auto-complete files, folders, and command names -Ctrl-x Ctrl-e OR Alt-e in zsh: Edit command line text in the editor (as defined by VISUAL environment variable)" + Ctrl-a: Go to the beginning of the line you are currently typing on + Ctrl-e: Go to the end of the line you are currently typing on + Ctrl-u: Remove text on the line before the cursor position + Ctrl-h: Remove preceding symbol (same as backspace) + Ctrl-w: Delete the word before the cursor + Ctrl-k: Remove text on the line after the cursor position + Ctrl-t: Swap the last two characters before the cursor + Alt-t: Swap the last two words before the cursor + Alt-f: Move cursor forward one word on the current line + Alt-b: Move cursor backward one word on the current line + Tab: Auto-complete files, folders, and command names + Ctrl-x Ctrl-e OR Alt-e in zsh: Edit command line text in the editor (as defined by VISUAL environment variable)" CONTROL="Job Control Shortcuts:: -Ctrl-c: Kill currently running process -Ctrl-d: Exit current shell -Ctrl-z: Suspend currently running process. fg restores it, and bg places it into background execution" + Ctrl-c: Kill currently running process + Ctrl-d: Exit current shell + Ctrl-z: Suspend currently running process. fg restores it, and bg places it into background execution" HISTORY="History Shortcuts:: -Ctrl-p: Previous line in the history -Ctrl-n: Next line in the history -Ctrl-r: Bring up next match backwards in shell history" + Ctrl-p: Previous line in the history + Ctrl-n: Next line in the history + Ctrl-r: Bring up next match backwards in shell history" if [ $# -lt 1 ]; then echo -e "${LINE}\n\n${CONTROL}\n\n${HISTORY}"