Skip to content

Instantly share code, notes, and snippets.

@LearnWebCode
Last active June 11, 2024 04:19
Show Gist options
  • Save LearnWebCode/694756ca49c57f254e3d8dc195fdfdc7 to your computer and use it in GitHub Desktop.
Save LearnWebCode/694756ca49c57f254e3d8dc195fdfdc7 to your computer and use it in GitHub Desktop.
My fzf first draft
# You need to give this file permission to execute by doing the following...
# chmod +x f.sh
# Add an alias named f to your .zshrc file like this:
# alias f="/Users/brad/Documents/shell-scripts/f.sh"
code "$(find ~/Documents ~/Desktop ~/Sites ~/Local\ Sites -type d \( -name "node_modules" -o -name ".next" -o -name ".git" -o -name "vendor" -o -name "wp-includes" -o -name "wp-admin" \) -prune -o -type d | fzf)"
# todo someday
# currently it only searches for folders, but it would be nice if I could search for zshrc or specific files, but I'm not sure if that will include too many files and be slow...
# If you press escape or control C and dont want to open any folder, dont feed code command an empty string, just dont run the command at all.
# Greatly, greatly, greatly reduce the folders we're finding, perhaps only search wp-content/themes etc or make better use of -maxdepth and -mindepth etc...
@esradev
Copy link

esradev commented Jun 11, 2024

Hi there. I generated this code by ChatGPT just for WordPress plugin and theme dev. I hope this help some one:

base_dir="/var/www/html"

search_paths=("$base_dir/*/wp-content/themes" "$base_dir/*/wp-content/plugins")

find_cmd="find ${search_paths[@]} -mindepth 1 -maxdepth 1"

find_cmd+=" -type d -print"

selected_dir=$(eval "$find_cmd" | fzf)

if [[ -n "$selected_dir" ]]; then
  workspace_file=$(find "$selected_dir" -maxdepth 1 -name "*.code-workspace" | head -n 1)
  
  if [[ -n "$workspace_file" ]]; then
    code "$workspace_file"
  else
    code "$selected_dir"
  fi
else
  echo "No directory selected."
fi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment