Open snafu4 opened 7 months ago
Fabric --list already exists
'fabric -l' just shows a list of patterns, which you then have to remember to type when you want to use that pattern. I'm suggesting a popup (with all of the available patterns shown) after you type '-p' so you just have to select one and it is inserted into the command line.
Maybe figured it out... This has only been tested on WSL2.
Add the following to ~/.bashrc
selectpattern() {
# Define the base directory
local basedir="./patterns"
# Use fzf to select a sub-directory from the sorted list in descending order
# Use sed to remove the base directory path from the output before presenting it to fzf
local selected=$(find "$basedir" -mindepth 1 -maxdepth 1 -type d | sed "s|^$basedir/||" | sort -r | fzf)
# Check if a directory was selected
if [ -n "$selected" ]; then
# No need to extract the basename since we've already manipulated the output
# Use printf to escape special characters in the directory name
printf -v escaped_dirname "%q" "$selected"
# Insert the directory name into the command line at the cursor position
READLINE_LINE="${READLINE_LINE:0:$READLINE_POINT}$escaped_dirname ${READLINE_LINE:$READLINE_POINT}"
READLINE_POINT=$(( READLINE_POINT + ${#escaped_dirname} + 1 ))
else
# If no directory was selected, ensure proper handling
echo "No directory selected."
fi
}
bind -x '"\C-p":selectpattern'
3. to use: CTRL-p whenever you want to list all of the patterns available (from the 'fabric' directory) use the arrow keys to go up/down and hit enter when you find the pattern you want
'''
> pbpaste | CTRL-p (and select 'extract_wisdom', press ENTER) and the results will be "pbpaste | extract_wisdom"
'''
4. Note: CTRL-p can be a quick substitute for 'fabric -l' to quickly see all available patterns.
5. Note: CTRL-p will only work from the directory where 'patterns' is a directory below (i.e. the 'fabric' directory).
6. Note: CTRL-p allows 'fuzzy search' so you can type "predict" and it will show all patterns that have predict in the name
The fabric -l
pattern isn't friendly for tools like fzf
. It' shows a "Patterns" header and indents all of the results. Can we create some sort of raw
flag that just lists the patterns and nothing else without a heading, line breaks, or indentations?
I'm willing to create a PR, but want to be on the same page with @danielmiessler and the mods.
What do you need?
After entering '-p', can you create some sort of binding (maybe to fzf) so that the list of available patterns pops up. A pattern is selected and lands on the CLI. I don't have the skillset to do this myself (I tried).