Skip to content

[bin] add dotfiles-bin-latest helper with optional fzf mode #28

Open

Description

@0xdevalias

Introduce a dotfiles-bin-latest utility (zsh function + alias) for quickly opening the most recently modified executables from ~/.dotfiles/bin in Sublime Text.

The current implementation defaults to opening the top 5 files in a new Sublime window, safely handling filenames with spaces or special characters. It also includes -h/--help and allows the count to be configurable.

Future enhancements:

  • Convert into a standalone script in ~/.dotfiles/bin for easier portability and reuse.
  • Add an interactive fzf mode with previews and keybindings (Enter to edit, Ctrl-O to open, Ctrl-Y to copy path, Ctrl-P to toggle preview, etc.), similar to the gist picker UI.

Below is a draft prototype that I vibed together with ChatGPT (GPT-5):

/usr/bin/env zsh

# TODO: Consider making this a proper standalone script in ~/.dotfiles/bin

# TODO: Add aa fzf mode with previews and interactive bindings
#   Reference for future fzf mode:
#   --------------------------------------------------------------------
#   local footer=$'Enter: Edit    Ctrl-O: Open    Ctrl-Y: Copy Path    Ctrl-P: Preview'
#  
#   ls -1t "$HOME/.dotfiles/bin" \
#     | ansifilter \
#     | sed 's/\*$//' \
#     | column -t \
#     | fzf \
#         --prompt 'dotfiles-bin> ' \
#         --ghost 'Type to filter files' \
#         --info=inline-right \
#         --input-border \
#         --footer "$footer" \
#         --footer-border=line \
#         --reverse \
#         --with-nth '1..' \
#         --accept-nth 1 \
#         --bind 'enter:execute(subl --new-window ~/.dotfiles/bin/{1})' \
#         --preview 'bat --style=plain --color=always ~/.dotfiles/bin/{1}' \
#         --preview-window 'right,50%,border-left,wrap,hidden' \
#         --bind 'ctrl-p:toggle-preview' \
#         --bind 'ctrl-o:execute-silent(open ~/.dotfiles/bin/{1})' \
#         --bind 'ctrl-y:execute-silent(
#           printf %s "$HOME/.dotfiles/bin/{1}" | pbcopy
#         )+transform-footer(echo Copied path to clipboard)+bg-transform-footer(
#           sleep 1; printf %s "$footer"
#         )' \
#         --bind 'click-footer:transform:
#           [[ $FZF_CLICK_FOOTER_WORD =~ Ctrl|Enter ]] && echo "trigger(${FZF_CLICK_FOOTER_WORD%:*})"
#         '
#   --------------------------------------------------------------------

# Open the latest files from ~/.dotfiles/bin in Sublime
# Usage:
#   dotfiles-bin-latest [COUNT]
#   dotfiles-bin-latest -h | --help
#
# Options:
#   COUNT       Number of latest files to open (default: 5)
#   -h, --help  Show this help message

_dotfiles-bin-latest() {
  local script_name="${0##*/}"
  local count=5

  # Parse arguments
  while [[ $# -gt 0 ]]; do
    case "$1" in
      -h|--help)
        cat <<EOF
Usage: $script_name [COUNT]

Open the latest executables from ~/.dotfiles/bin in Sublime Text.

Options:
  COUNT       Number of latest files to open (default: 5)
  -h, --help  Show this help message
EOF
        return 0
        ;;
      *)
        count="$1"
        ;;
    esac
    shift
  done

  ls -1t "$HOME/.dotfiles/bin" \
    | ansifilter \
    | sed 's/\*$//' \
    | head -n "$count" \
    | while IFS= read -r f; do
        printf '%s\0' "$HOME/.dotfiles/bin/$f"
      done \
    | xargs -0 subl --new-window
}

alias dotfiles-bin-latest="_dotfiles-bin-latest"

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions