Skip to content

Commit c3ff0c1

Browse files
devydevy
authored andcommitted
add re_run function
1 parent 0988856 commit c3ff0c1

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

functions/re_run.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/sh
2+
3+
# Function: re_run
4+
# Description: refresh and rerun the last bash function
5+
# Usage: re_run [arguments]
6+
# Alias: rr
7+
8+
function re_run() {
9+
# Function implementation goes here
10+
# Get the last command from history
11+
local last_command=$(history | tail -n 1 | sed 's/^[[:space:]]*[0-9]*[[:space:]]*//')
12+
13+
# Check if we have a command
14+
if [ -z "$last_command" ]; then
15+
echo "No previous command found in history"
16+
return 1
17+
fi
18+
19+
# Execute the last command with any additional arguments
20+
echo "${green}Reloading ...${reset}"
21+
source ~/.zshrc &&
22+
echo "${green}Re-running: $last_command $* ${reset}"
23+
eval "$last_command $*"
24+
}
25+
26+
# Create alias
27+
alias rr="re_run"

0 commit comments

Comments
 (0)