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

Using hardcore mode will break cp ../../ with ohmyzsh directory aliases #33

Open
eigan opened this issue Feb 25, 2018 · 6 comments
Open

Comments

@eigan
Copy link

eigan commented Feb 25, 2018

Summary

This bug is encountered because of an alias built-in to oh-my-zsh. Using cp ... does not work.

How to reproduce

Test directory:

.
├── file
└── start
    └── level
        └── level

Configuration:

YSU_MODE=ALL
YSU_HARDCORE=1

Commands to execute

$ cd start/level/level
$ cp ../../../file.txt .
Found existing global alias for "../..". You should use: "..."
Found existing global alias for "../../..". You should use: "...."
You Should Use hardcore mode enabled. Use your aliases!
$  cp ..../file.txt .
cp: cannot stat '..../file.txt': No such file or directory
cp .../../file.txt .
Found existing global alias for "../..". You should use: "..."
You Should Use hardcore mode enabled. Use your aliases!

The aliases for "..." is defined here: https://github.com/robbyrussell/oh-my-zsh/blob/master/lib/directories.zsh

@MichaelAquilina
Copy link
Owner

I'm not entirely certain what the bug is from reading this bug report.

Could you give an example of expected behaviour and actual behaviour? I think the bug is that cp .../../file.txt should be suggested as ..../file.txt but I'm not entirely sure

@eigan
Copy link
Author

eigan commented Feb 26, 2018

Sorry, should have made it more clear. This plugin suggest to rewrite the command ( cp ../../../file.txt ) to something that does not work ( cp ..../file.txt . )

It correctly says that .... is an alias, but it cannot be used with cp (as seen in example: (cannot stat ..../file.txt etc))

This could be a bug with oh-my-zsh, I am not sure..

@MichaelAquilina
Copy link
Owner

ah. Why does .... exist as an alias if it doesn't work?

@eigan
Copy link
Author

eigan commented Feb 26, 2018

The aliases for "..." is defined here: https://github.com/robbyrussell/oh-my-zsh/blob/master/lib/directories.zsh

It is sourced here: https://github.com/robbyrussell/oh-my-zsh/blob/master/oh-my-zsh.sh#L31

The aliases are checked in _check_global_aliases().

This code on line 71:. if [[ "$1" = *"$v"* ]]; then will match any commands containing the alias defined. So the alias ...='../..' will match when I type cp ../../ and zsh-you-should-use will complain that I am not using this alias.

Note that whatever command I type which include ../.., zsh-you-should-use will complain:

$ ls ../../
Found existing global alias for "../..". You should use: "..."
You Should Use hardcore mode enabled. Use your aliases!

Edit, using ls ... actually works, so this was a bad example. But mv .../file.txt . does not.

I have solved it by doing this:

@@ -68,7 +68,7 @@ function _check_global_aliases() {
     # Need to remove leading and trailing ' if they exist
     v="${(Q)tokens[2]}"
 
-    if [[ "$1" = *"$v"* ]]; then
+    if [[ "$1" = "$v"* ]]; then
       ysu_global_message "$v" "$k"
       found=true
     fi

@eigan
Copy link
Author

eigan commented Feb 26, 2018

ah. Why does .... exist as an alias if it doesn't work?

It does work.

$ pwd
/home/einar/tmp/test
$ ....
$ pwd
/home

@eigan
Copy link
Author

eigan commented Feb 26, 2018

Oh,

$ ls ...

This command actually works. But cp .../file.txt, mv .../file.txt etc does not.

Edit: Sorry for all the spamming :|

@MichaelAquilina MichaelAquilina changed the title Using hardcode mode will break cp ../../ with ohmyzsh directory aliases Using hardcore mode will break cp ../../ with ohmyzsh directory aliases Oct 13, 2019
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

No branches or pull requests

2 participants