Skip to content

Conversation

ktchen14
Copy link

@ktchen14 ktchen14 commented Nov 13, 2019

This is an alternative to #406. It fixes #413 and uses bash native functionality instead of ls at all. The impetus for this change is that an alias to ls breaks chruby. Specifically in my case I have:

alias ls=exa

Which doesn't have a -A flag.

@havenwood
Copy link
Collaborator

A shell-based solution would need to be portable to zsh since chruby support bash and zsh.

For the moment, you can source chruby before you set your exa alias for a fix.

@havenwood havenwood self-requested a review November 13, 2019 19:12
Copy link
Collaborator

@havenwood havenwood left a comment

Choose a reason for hiding this comment

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

This would need to either be implemented portably for bash/zsh or you could do a if statement with a bash- and zsh-specific version.

Adding proper ordering would be a real win.

@@ -1,10 +1,14 @@
CHRUBY_VERSION="0.3.9"
RUBIES=()

saveglob="$(shopt -p nullglob dotglob)"
Copy link
Collaborator

Choose a reason for hiding this comment

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

In zsh, the shopt equivalent would be setopt.

for dir in "$PREFIX/opt/rubies" "$HOME/.rubies"; do
[[ -d "$dir" && -n "$(ls -A "$dir")" ]] && RUBIES+=("$dir"/*)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Another thing to consider is the sort order. In zsh, you can get a proper numeric sort fairly easily, so 2.10 is greater than 2.9.

Here is a zsh one-liner.

echo "${(@n)RUBIES}"

Or to print each Ruby in order:

printf "%s\n" "${(@n)RUBIES:t}"

@havenwood
Copy link
Collaborator

See #278 for a stab at numeric sorting. We discussed the possibility of creating a shell library for portable numeric sorting, since it's an annoying gap. I'm for switching to a portable shell solution but think it should fix the numeric sorting issue too.

@ktchen14
Copy link
Author

@havenwood I just pushed a new version of the code which should be zsh compatible. I don't really use zsh but from a careful reading of the documentation this is the simplest version that I think works for both bash and zsh.

@ktchen14
Copy link
Author

Also this doesn't handle ordering. That looks hard to do in a portable fashion and I believe is out of scope for this PR.

@ktchen14
Copy link
Author

ktchen14 commented Dec 3, 2019

Ping. Please let me know if there are any changes I should make or if I should close this PR. Thanks!

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.

alias for ls breaks chruby.sh
2 participants