From 7eeeb9e85d482ea3fe16f3644d8d5784521d12c5 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Wed, 5 Jun 2024 12:10:26 +0200 Subject: [PATCH] sh: Add clear and rerun function Added simple function to clear the screen but additionally re-run the last executed command. Mirroring my clear screen alias `cl`, this one is executed with `cll` (clear-and-last) currently. It comes in useful for me every now and again because I sometimes just need a quick way to get rid of 'clutter' on my terminal (e.g. running multiple rg invocations after each other, or diffs, or anything that spews a bunch of stuff on screen and I want to find specific things afterwards). I am very used to running `cl` and then the second to last history item. This makes those additional keystrokes unnecessary. --- sh/.config/sh/alias | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sh/.config/sh/alias b/sh/.config/sh/alias index ae0edbf..f316329 100644 --- a/sh/.config/sh/alias +++ b/sh/.config/sh/alias @@ -43,6 +43,14 @@ alias md="mkdir -p" # clear my screen alias cl="clear" +# clear screen AND re-run last command +# Is presumably not fully portable, see +# https://overflow.hostux.net/questions/24223811/getting-last-executed-command-from-script# +cll() { + lastfun="$(fc -n -l -1 -1)" + clear + eval "$lastfun" +} # Display current external ip address alias myip="curl -s icanhazip.com"