From 608acc627c7588ff0d3e4bd1844b295c92688784 Mon Sep 17 00:00:00 2001 From: Chen Asraf Date: Fri, 10 Oct 2025 00:12:04 +0300 Subject: [PATCH] feat: add hsc function to list all custom plugin functions --- plugins/ascii-font.plugin.zsh | 1 - plugins/ascii_font/ascii_font.plugin.zsh | 122 +++++++++++++++++++++++ plugins/ascii_font/ascii_font.zsh | 121 ---------------------- plugins/list_functions.zsh | 44 ++++++++ plugins/motd/10-logo | 2 +- 5 files changed, 167 insertions(+), 123 deletions(-) delete mode 100755 plugins/ascii-font.plugin.zsh create mode 100755 plugins/ascii_font/ascii_font.plugin.zsh delete mode 100755 plugins/ascii_font/ascii_font.zsh create mode 100644 plugins/list_functions.zsh diff --git a/plugins/ascii-font.plugin.zsh b/plugins/ascii-font.plugin.zsh deleted file mode 100755 index 4e681915..00000000 --- a/plugins/ascii-font.plugin.zsh +++ /dev/null @@ -1 +0,0 @@ -ascii-text() { ${0:A:h}/ascii_font/ascii_font.zsh } diff --git a/plugins/ascii_font/ascii_font.plugin.zsh b/plugins/ascii_font/ascii_font.plugin.zsh new file mode 100755 index 00000000..d7248906 --- /dev/null +++ b/plugins/ascii_font/ascii_font.plugin.zsh @@ -0,0 +1,122 @@ +#!/usr/bin/env zsh + +ascii-text() { + # ascii-font() { + dir="$DOTFILES/plugins/ascii_font" + font="$dir/fonts/Big-Money-ne" + size=1 + color="" + bg="" + bold="" + reset="$(tput sgr0)" + + while [ $# -gt 0 ]; do + case "$1" in + -f | --font) + if [[ -f "$dir/fonts/$2.flf" ]]; then + font="$dir/fonts/$2" + else + font="$2" + fi + shift 2 + ;; + -s | --size) + size="$2" + shift 2 + ;; + -c | --color) + if [[ $2 == "rainbow" ]]; then + color="rainbow" + else + color="$(tput setaf $2)" + fi + shift 2 + ;; + -b | --bg) + bg="$(tput setab $2)" + shift 2 + ;; + -B | --bold) + bold="$(tput bold)" + shift + ;; + -l | --list) + echo "Available fonts:" + echo + figlist | tail --lines=+4 + return 0 + ;; + --show-fonts) + showfigfonts | less + return 0 + ;; + -v | --version) + echo "ascii-font 1.0.0" + echo "Written by Chen Asraf " + return 0 + ;; + -h | --help) + echo "Usage: ascii-font [OPTION]... [TEXT]..." + echo "Convert text to ASCII art." + echo + echo " -h, --help display this help and exit" + echo " -f, --font specify font (default: standard)" + echo " -s, --size specify font size (default: 1)" + echo " -c, --color specify font color (default: 0)" + echo " -b, --bg specify background color (default: 0)" + echo " -B, --bold set font bold" + echo " -C, --no-center Disable centering the text" + echo " -l, --list list available fonts" + echo " -v, --version display version information and exit" + echo + echo "See color options at:" + echo " $(tput smul)https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit" + echo + echo "Report bugs to Chen Asraf " + return 0 + ;; + *) + break + ;; + esac + + done + + if [[ ! -f $(which figlet) ]]; then + echo "figlet not found. Install? [y/N] " + read -r install + + if [[ $install != "y" ]]; then + echo_red "figlet not installed. Aborting" + return 1 + fi + + if is_mac; then + brew install figlet + else + apt install figlet + fi + fi + + if [[ ! -f $(which lolcat) ]]; then + echo "lolcat not found. Install? [y/N] " + read -r install + + if [[ $install != "y" ]]; then + echo_red "lolcat not installed. Aborting" + return 1 + fi + + if is_mac; then + brew install lolcat + else + apt install lolcat + fi + fi + + if [[ $color != "rainbow" ]]; then + echo "$bold$color$bg$(figlet -f $font -w $(tput cols) -c "$@")$reset" + else + echo "$bold$bg$(figlet -f $font -w $(tput cols) -c "$@" | lolcat -f)$reset" + fi +} diff --git a/plugins/ascii_font/ascii_font.zsh b/plugins/ascii_font/ascii_font.zsh deleted file mode 100755 index 62a02312..00000000 --- a/plugins/ascii_font/ascii_font.zsh +++ /dev/null @@ -1,121 +0,0 @@ -#!/usr/bin/env zsh - -# ascii-font() { -dir="$DOTFILES/plugins/ascii_font" -font="$dir/fonts/Big-Money-ne" -size=1 -color="" -bg="" -bold="" -reset="$(tput sgr0)" - -while [ $# -gt 0 ]; do - case "$1" in - -f | --font) - if [[ -f "$dir/fonts/$2.flf" ]]; then - font="$dir/fonts/$2" - else - font="$2" - fi - shift 2 - ;; - -s | --size) - size="$2" - shift 2 - ;; - -c | --color) - if [[ $2 == "rainbow" ]]; then - color="rainbow" - else - color="$(tput setaf $2)" - fi - shift 2 - ;; - -b | --bg) - bg="$(tput setab $2)" - shift 2 - ;; - -B | --bold) - bold="$(tput bold)" - shift - ;; - -l | --list) - echo "Available fonts:" - echo - figlist | tail --lines=+4 - return 0 - ;; - --show-fonts) - showfigfonts | less - return 0 - ;; - -v | --version) - echo "ascii-font 1.0.0" - echo "Written by Chen Asraf " - return 0 - ;; - -h | --help) - echo "Usage: ascii-font [OPTION]... [TEXT]..." - echo "Convert text to ASCII art." - echo - echo " -h, --help display this help and exit" - echo " -f, --font specify font (default: standard)" - echo " -s, --size specify font size (default: 1)" - echo " -c, --color specify font color (default: 0)" - echo " -b, --bg specify background color (default: 0)" - echo " -B, --bold set font bold" - echo " -C, --no-center Disable centering the text" - echo " -l, --list list available fonts" - echo " -v, --version display version information and exit" - echo - echo "See color options at:" - echo " $(tput smul)https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit" - echo - echo "Report bugs to Chen Asraf " - return 0 - ;; - *) - break - ;; - esac - -done - -if [[ ! -f $(which figlet) ]]; then - echo "figlet not found. Install? [y/N] " - read -r install - - if [[ $install != "y" ]]; then - echo_red "figlet not installed. Aborting" - return 1 - fi - - if is_mac; then - brew install figlet - else - apt install figlet - fi -fi - -if [[ ! -f $(which lolcat) ]]; then - echo "lolcat not found. Install? [y/N] " - read -r install - - if [[ $install != "y" ]]; then - echo_red "lolcat not installed. Aborting" - return 1 - fi - - if is_mac; then - brew install lolcat - else - apt install lolcat - fi -fi - -if [[ $color != "rainbow" ]]; then - echo "$bold$color$bg$(figlet -f $font -w $(tput cols) -c "$@")$reset" -else - echo "$bold$bg$(figlet -f $font -w $(tput cols) -c "$@" | lolcat -f)$reset" -fi -# } diff --git a/plugins/list_functions.zsh b/plugins/list_functions.zsh new file mode 100644 index 00000000..9c4be322 --- /dev/null +++ b/plugins/list_functions.zsh @@ -0,0 +1,44 @@ +#!/usr/bin/env zsh + +list_exported_functions() { + local file + for file in "$@"; do + # Get unset functions from this file + local unset_funcs=$(grep -oE 'unset\s+-f\s+[a-zA-Z0-9_-]+' "$file" 2>/dev/null | \ + awk '{print $3}') + + # Parse function definitions directly from the file + # Matches: function_name() or function function_name() + grep -oE '^\s*(function\s+)?[a-zA-Z0-9_-]+\s*\(\)' "$file" 2>/dev/null | \ + sed -E 's/^[[:space:]]*//' | \ + sed -E 's/^function[[:space:]]+//' | \ + sed 's/()$//' | \ + grep -v -E '^(_.*|comp.*|bashcomp.*|autoload_completions|complete)$' | \ + while read -r func; do + # Skip if this function was unset + if ! echo "$unset_funcs" | grep -qx "$func"; then + echo "$func" + fi + done + done +} + +hscl() { + # Get the plugins directory (directory of this script) + local plugins_dir="$DOTFILES/plugins" + + # Find all script files in plugins directory and subdirectories + local script_files=("${plugins_dir}"/**/*.zsh(N)) + + # Get all exported functions, sort and deduplicate, then pipe to fzf local selected + list_exported_functions "${script_files[@]}" +} + +hsc() { + selected=$(hscl | sort -u | fzf --prompt="Select function: ") + + # If a function was selected, prefill it in the shell + if [[ -n "$selected" ]]; then + print -z "$selected" + fi +} diff --git a/plugins/motd/10-logo b/plugins/motd/10-logo index 9be1d46b..fc735c6d 100755 --- a/plugins/motd/10-logo +++ b/plugins/motd/10-logo @@ -1,7 +1,7 @@ #!/usr/bin/env zsh source "$DOTFILES/aliases.zsh" -ascii-text() { . $DOTFILES/plugins/ascii_font/ascii_font.zsh } +source $DOTFILES/plugins/ascii_font/ascii_font.plugin.zsh if [[ $(hostname) == 'spider.casraf.dev' ]]; then text='@spider'