-
Notifications
You must be signed in to change notification settings - Fork 1
/
install_grepit.sh
47 lines (40 loc) · 1.3 KB
/
install_grepit.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash
# Install fzf if not already installed
if ! command -v fzf &> /dev/null; then
echo "Installing fzf..."
sudo apt update
sudo apt install -y fzf
else
echo "fzf is already installed."
fi
# Define the updated grepit function with history recording
grepit_function="
grepit() {
local search_term=\"\$1\"
local cmd
if [ -n \"\$search_term\" ]; then
cmd=\$(history | tac | grep \"\$search_term\" | fzf --height=100% --layout=reverse --border --prompt=\"Select command to run: \" --no-preview | sed 's/^[ ]*[0-9]*[ ]*//')
else
cmd=\$(history | tac | fzf --height=100% --layout=reverse --border --prompt=\"Select command to run: \" --no-preview | sed 's/^[ ]*[0-9]*[ ]*//')
fi
if [ -n \"\$cmd\" ]; then
echo \"Running: \$cmd\"
# Add the selected command to the history
history -s \"\$cmd\"
eval \"\$cmd\"
else
echo \"No command selected.\"
fi
}
"
# Add the grepit function to .bashrc if it's not already present
if ! grep -q "grepit()" ~/.bashrc; then
echo "Adding grepit function to ~/.bashrc..."
echo "$grepit_function" >> ~/.bashrc
else
echo "grepit function is already in ~/.bashrc"
fi
# Source the .bashrc file to apply changes
echo "Sourcing ~/.bashrc..."
source ~/.bashrc
echo "Setup complete."