Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert changes #4

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Revert changes #4

wants to merge 1 commit into from

Conversation

p1r473
Copy link
Contributor

@p1r473 p1r473 commented May 29, 2024

Hi,
I think we need to revert these changes - they introduced errors when tested
Sorry about that!

Copy link

Review changes with SemanticDiff.

Copy link
Contributor Author

@p1r473 p1r473 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed

Copy link
Owner

@MohamedElashri MohamedElashri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we still can make this generic because i.e. Debian will have fdfind.

Something like this will be better

# Unalias existing aliases if they exist
unalias find 2>/dev/null
unalias fd 2>/dev/null

# Check if fd or fdfind is installed
if (( $+commands[fd] )); then
  alias fd='fd'
elif (( $+commands[fdfind] )); then
  alias fd='fdfind'
else
  print "zsh-fd-plugin: neither 'fd' nor 'fdfind' found on path. Please install 'fd' before using this plugin." >&2
  return 1
fi

@p1r473
Copy link
Contributor Author

p1r473 commented Jun 8, 2024

Sure!
Do you think we should unalias someone's alias?

@MohamedElashri
Copy link
Owner

MohamedElashri commented Jun 8, 2024

Sure! Do you think we should unalias someone's alias?

Do you mean having that?

unalias find 2>/dev/null

We are re-aliasing it if there is one anyway. The shell will use the last definition occurrence in zshrc.

I pushed some fix myself, but it seems that it introduced problem on Mac. So I want to have something more suitable.

I'm thinking of more elegant way like that

# Project:  fd-zsh
# File:     fd-zsh-plugin.zsh
# Author:   Mohamed Elashri
# Email:    [email protected]

# Unalias existing aliases if they exist
unalias find 2>/dev/null
unalias fd 2>/dev/null

# Check if fd or fdfind is installed
if (( $+commands[fd] )); then
  alias fd='fd'
elif (( $+commands[fdfind] )); then
  alias fd='fdfind'
else
  echo "zsh-fd-plugin: neither 'fd' nor 'fdfind' found on path. Please install 'fd' before using this plugin." >&2
  return 1
fi

# General aliases
alias find='fd'
alias fd='fd --color always' # Always colorize output by default

# Function to handle fd aliases
fd_aliases() {
  case "$1" in
    details)    fd --list-details ;;
    ext)        fd --extension "$2" ;;
    name)       fd --glob "$2" ;;
    case)       fd --ignore-case ;;
    hidden)     fd --hidden ;;
    abs)        fd --absolute-path ;;
    exec)       fd --exec "$2" ;;
    exclude)    fd --exclude "$2" ;;
    size)       fd --size "$2" ;;
    owner)      fd --owner "$2" ;;
    symbolic)   fd --follow ;;
    version)    fd --version ;;
    help)       fd --help ;;
    *)          echo "Unknown option: $1" ;;
  esac
}

# Aliases using the fd_aliases function
alias fd_details='fd_aliases details'
alias fd_ext='fd_aliases ext'
alias fd_name='fd_aliases name'
alias fd_case='fd_aliases case'
alias fd_hidden='fd_aliases hidden'
alias fd_abs='fd_aliases abs'
alias fd_exec='fd_aliases exec'
alias fd_exclude='fd_aliases exclude'
alias fd_size='fd_aliases size'
alias fd_owner='fd_aliases owner'
alias fd_symbolic='fd_aliases symbolic'
alias fd_version='fd_aliases version'
alias fd_help='fd_aliases help'

@p1r473
Copy link
Contributor Author

p1r473 commented Jun 12, 2024

Sure!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants