From d7aa17d02ca31fafecbc9c7b1a74cb1308c10a9f Mon Sep 17 00:00:00 2001 From: Ryan Collingham Date: Sun, 16 Jul 2017 17:29:22 +0100 Subject: [PATCH 1/4] Trap ctrl-c and clean up --- git-recall | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/git-recall b/git-recall index 8b1a358..927f78d 100644 --- a/git-recall +++ b/git-recall @@ -1,7 +1,5 @@ #!/usr/bin/env bash - - # usage info usage() { cat <&2 # END capture From 8db954a2d62e9e35a85f56ca44859278eec3bdda Mon Sep 17 00:00:00 2001 From: Ryan Collingham Date: Mon, 17 Jul 2017 11:52:21 +0100 Subject: [PATCH 2/4] Cleanup diff gracefully --- git-recall | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/git-recall b/git-recall index 927f78d..91e2ea2 100644 --- a/git-recall +++ b/git-recall @@ -191,15 +191,23 @@ function get_diff() { DIFF_LINES_NUMBER=$(( DIFF_LINES_NUMBER + off )) } +cleanup_diff() +{ + clear_screen + cleanup_and_exit +} + # This function will print the diff according the commit's tip. If the diff is too long, the result will be displayed using 'less'. function print_diff() { get_diff if [[ $(( TN + DIFF_LINES_NUMBER + OFFSET )) -ge $(( `tput lines` - 1 )) ]]; then + trap cleanup_diff INT if [[ $LESSKEY = true ]]; then - echo "$DIFF" | less -r -k $HOME/.lsh_less_keys_tmp + (echo "$DIFF" | less -r -k $HOME/.lsh_less_keys_tmp) else - echo "$DIFF" | less -r + (echo "$DIFF" | less -r) fi + trap cleanup_and_exit INT clear_screen else stop=false From a6fce2c863eda7eaea06bc602c224d35a73db9a4 Mon Sep 17 00:00:00 2001 From: Ryan Collingham Date: Mon, 24 Jul 2017 10:33:16 +0100 Subject: [PATCH 3/4] Remove unintended whitespace changes --- git-recall | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/git-recall b/git-recall index 2b93e34..5a9cc3e 100644 --- a/git-recall +++ b/git-recall @@ -1,5 +1,6 @@ #!/usr/bin/env bash + # usage info usage() { cat < Date: Tue, 1 Aug 2017 22:17:48 +0100 Subject: [PATCH 4/4] Restore original stty settings --- git-recall | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/git-recall b/git-recall index 5a9cc3e..6c04b88 100644 --- a/git-recall +++ b/git-recall @@ -263,9 +263,13 @@ cleanup_and_exit() tput cnorm # unhide cursor echo "$NORMAL" # normal colors + stty "$orig_stty" > /dev/null 2>&1 exit } +# Store original terminal settings +orig_stty=$(stty -g) + # Catch a control-C interrupt and perform cleanup operations before exiting trap cleanup_and_exit INT