wd icon indicating copy to clipboard operation
wd copied to clipboard

Bug report: wd show command does not work for directories under home

Open kelbyers opened this issue 2 years ago • 12 comments

Describe the bug wd show is not correctly showing warp points that are located within my home directory structure. Warp points that just go to $HOME do show up with the show command.

To Reproduce Steps to reproduce the behavior:

  1. create and cd to a temporary unique directory in your home directory: cd $(mktemp -d ~/tmp.XXXXXXXX)
  2. add a warp point to the directory: wd add mytmp1
  3. make sure the warp point was added: wd list
  4. check for defined warp points to the current directory: wd show

Expected behavior A response that one warp point is defined for the current directory:

 * 1 warp point(s) to current directory: mytmp1

Screenshots

➜ cd $(mktemp -d ~/tmp.XXXXXXXX)
➜ wd add mytmp1
 * Warp point added
➜ wd list
 * All warp points:
ci-cd-scripts  ->  ~/git/ose-automation-stores/ci-cd-scripts
       mytmp1  ->  ~/tmp.7vczbdgF
➜ wd show
 * No warp point to ~/tmp.7vczbdgF

Desktop (please complete the following information):

  • zsh version: zsh 5.8 (x86_64-apple-darwin19.6.0)
  • wd version: wd version 0.5.0

Additional context I do see that there is a version of wd tagged as 0.5.1. The version that I have is installed using zgenom load mfaerevaag/wd, and it displays its version as 0.5.0.

kelbyers avatar Feb 17 '22 17:02 kelbyers

Strange, I can't reproduce with exactly your steps. Does wd show work for other warp points?

altschuler avatar Feb 17 '22 18:02 altschuler

wd show works for anything that is not a subdirectory of my home directory. Also, it does not matter whether I specify a full path or not when adding the warp point (although I think I played around with specifying the second parameter to wd add and it might be ignoring everything after the first parameter):

➜ cd /usr/local

➜ wd add ul
 * Warp point added

➜ wd show
 * 1 warp point(s) to current directory: ul

➜ wd list
 * All warp points:
ci-cd-scripts  ->  ~/git/ose-automation-stores/ci-cd-scripts
   st-promote  ->  ~/git/ose-automation-stores/ci-cd-scripts
           ul  ->  /usr/local
       wrench  ->  ~/git/ose-automation-puppet/service-now-wrench

➜ cd

➜ cd Applications

➜ pwd
/Users/jxb2016/Applications

➜ wd add apps /Users/jxb2016/Applications
 * Warp point added

➜ wd show
 * No warp point to ~/Applications

➜ wd list
 * All warp points:
         apps  ->  ~/Applications
ci-cd-scripts  ->  ~/git/ose-automation-stores/ci-cd-scripts
   st-promote  ->  ~/git/ose-automation-stores/ci-cd-scripts
           ul  ->  /usr/local
       wrench  ->  ~/git/ose-automation-puppet/service-now-wrench

kelbyers avatar Feb 18 '22 17:02 kelbyers

Hmm. wd show <point> does work:

➜ wd show apps
 * Warp point: apps -> ~/Applications

kelbyers avatar Feb 18 '22 17:02 kelbyers

Might be a macOS specific issue, I don't have one to test on though. Could you try to run the test suite? Just clone this repo, cd into to the test directory and run ./tests.sh.

altschuler avatar Feb 18 '22 23:02 altschuler

Sorry about taking so long. I have run the tests:

➜ /bin/zsh ./tests.sh
test_empty_config
ASSERT:should initially be an empty config expected:<0> but was:<       0>
test_simple_add_remove
ASSERT:should have 1 wps expected:<1> but was:<       1>
ASSERT:wps should be empty expected:<0> but was:<       0>
test_default_add_remove
ASSERT:should have 1 wps expected:<1> but was:<       1>
ASSERT:wps should be empty expected:<0> but was:<       0>
test_no_duplicates
test_default_no_duplicates
test_default_multiple_directories
test_valid_identifiers
test_removal
test_list
ASSERT:should only be one warp point expected:<       2> but was:<2>
ASSERT:should be more than one warp point expected:<       3> but was:<3>
test_show
test_quiet
test_clean
test_ls
test_path
test_config
ASSERT:expected:<1> but was:<       1>

Ran 15 tests.

FAILED (failures=8)

kelbyers avatar Mar 04 '22 21:03 kelbyers

Looks to me like the difference is in the output of the wc command. The version that comes with MacOS seems to indent the output.

➜ grep wd tests.sh | wc -l
      72

Here is the output from gnu's wc:

wd/test at C02W11Y6HTD6MBP on  master
➜ grep wd tests.sh | gwc -l
72

kelbyers avatar Mar 04 '22 21:03 kelbyers

One thing that I notice looking at the code for wd_show. When figuring out the current directory to look for in the list of warp points, it runs: PWD="${PWD/$HOME/~}". My understanding is that the intent of that is turn something like /Users/kelbyers/git into ~/git. That doesn't seem to work, at least on my MacOS:

➜ echo $HOME
/Users/kelbyers

➜ echo $PWD
/Users/kelbyers/git/mfaerevaag/wd/test

➜ echo ${PWD/$HOME/~}
/Users/kelbyers/git/mfaerevaag/wd/test

The substitution does work, in general, but I think the / in $HOME are effecting it:

➜ echo ${PWD/kelbyers/HOME}
/Users/HOME/git/mfaerevaag/wd/test

kelbyers avatar Mar 04 '22 21:03 kelbyers

Well, ignore my comment above. I looks like the substitution does work when I quote it:

➜ echo "${PWD/$HOME/~}"
~/git/mfaerevaag/wd/test

kelbyers avatar Mar 04 '22 21:03 kelbyers

Running with debug output (set -x ; wd show):

➜ pwd
/Users/kelbyers/git
➜ wd list | grep ' git'
          git  ->  ~/git
+/Users/jxb2016/git/mfaerevaag/wd/wd.sh:460> wd_show ''
+wd_show:2> local name_arg=''
+wd_show:4> [[ -n '' ]]
+wd_show:14> local wd_matches
+wd_show:15> wd_matches=( )
+wd_show:17> PWD='~/git'
+wd_show:18> [[ '' == \~/git ]]
+wd_show:30> echo '~/git'
+wd_show:30> sed 's:/Users/kelbyers:~:'
+wd_show:30> wd_print_msg '\033[93m' 'No warp point to ~/git'
+wd_print_msg:2> [[ -z '' ]]
+wd_print_msg:4> local color='\033[93m'
+wd_print_msg:5> local msg='No warp point to ~/git'
+wd_print_msg:7> [[ '\033[93m' ==  || 'No warp point to ~/git' ==  ]]
+wd_print_msg:11> print ' \033[93m*\033[m No warp point to ~/git'
 * No warp point to ~/git

kelbyers avatar Mar 04 '22 21:03 kelbyers

Looks like the issue may be being caused by how the warp point is formatted when it's saved - it's not matching anything when it's being looked up here.

From your WD_CONFIG (which is ~/.warprc IIRC, unless you've changed it), how is the warp point saved? Is the path /Users/kelbyers/git, or ~/git? I'm expecting the former, else I have no clue why the lookup fails

alpha-tango-kilo avatar Mar 13 '22 18:03 alpha-tango-kilo

Alternatively, adding an echo "$points" after points is loaded may show the same information

alpha-tango-kilo avatar Mar 13 '22 18:03 alpha-tango-kilo

the saved warp points are like this:

➜ cat ~/.warprc
ci-cd-scripts:~/git/ose-automation-stores/ci-cd-scripts
git:~/git
puppet-ci:~/git/ose-automation-puppet/puppet-ci
st-promote:~/git/ose-automation-stores/ci-cd-scripts
thdlib:~/git/ose-automation-puppet/thdlib
trinity1:~/git/ose-automation-puppet/puppet-ci
wrench:~/git/ose-automation-puppet/service-now-wrench

kelbyers avatar Mar 15 '22 17:03 kelbyers

I have the same symptoms and it looks like the zsh option extended_glob is causing this at my end:

~/projects/zshorg master[8fc846b] ✔ $                                                                                                               [12:09]
 ❯ wd show
 * No warp point to ~/projects/zshorg

 ~/projects/zshorg master[8fc846b] ✔ $                                                                                                               [12:09]
 ❯
 ❯ setopt noextendedglob

 ~/projects/zshorg master[8fc846b] ✔ $                                                                                                               [12:10]
 ❯ wd show
 * 1 warp point(s) to current directory: zo

 ~/projects/zshorg master[8fc846b] ✔ $                                                                                                               [12:10]

Before I turned to my zsh setup and deactivated active options one at a time (kidding, I was going to, but extended_glob was the first candidate), I introduced debug prints all over the place, and that was strange:

* Comparing '~/projects/zshorg' -> '~/projects/zshorg'

The strings look the same, but aren't from zsh's point of view.

I'm using ubuntu 20.04, zsh 5.8.

tomterl avatar Oct 06 '22 10:10 tomterl

Comparing '~/projects/zshorg' -> '~/projects/zshorg'

This is why I never found the issue, because the things were literally equal (to my puny human eyes), thank you for finding this!

alpha-tango-kilo avatar Oct 06 '22 12:10 alpha-tango-kilo

@kelbyers do you have extend_glob set in your setup, or is this possibly something else on macOS?

tomterl avatar Oct 06 '22 15:10 tomterl

Closing as fixed until we hear otherwise, I'll cut a v0.5.2 release shortly. Thank you very much tomterl!

alpha-tango-kilo avatar Oct 06 '22 17:10 alpha-tango-kilo