Created
June 8, 2024 08:47
-
-
Save sourab-jadav/46800e7a740afe9f077853dd1427375e to your computer and use it in GitHub Desktop.
fuzzy finds through the commands
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Path to the commands file | |
COMMANDS_FILE=~/commands.txt | |
# Check if the commands file exists | |
if [[ ! -f $COMMANDS_FILE ]]; then | |
echo "Commands file not found!" | |
exit 1 | |
fi | |
# Use fzf to fuzzy find a command from the file | |
SELECTED_LINE=$(cat $COMMANDS_FILE | fzf) | |
# If a line was selected, extract and execute the command | |
if [[ -n "$SELECTED_LINE" ]]; then | |
# Extract the command using one or more spaces as the delimiter | |
COMMAND=$(echo "$SELECTED_LINE" | awk -F' + ' '{print $1}') | |
# Execute the command | |
echo "Executing: $COMMAND" | |
eval "$COMMAND" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ls -l List files in long format
cd .. Move to the parent directory
rm -rf Remove files and directories recursively and forcefully
grep Search for patterns within files
htop Interactive process viewer
df -h Display disk space usage in human-readable format
add these commands or any commands of your choice in commands.txt file
NOTE: info about the command and what it does should be kept in a single line :)