Hacker News new | ask | show | jobs
by oemera 5591 days ago
Thank you for this awesome little script. However I found out that bashmarks doesn't work with folders which have whitespaces in the name.

For example:

  cd /Users/username/Library/Application\ Support
  s app_support
works great but if you do this it won't work:

  g app_support
I opened an issue on GitHub and after that I tried to fix it on my own. I never wrote a bash script and I'm really proud to have fixed this problem on my own.

Here are changes I made:

  # save current directory to bookmarks
  touch ~/.sdirs
  function s {
     cat ~/.sdirs | grep -v "export DIR_$1=" > ~/.sdirs1
     mv ~/.sdirs1 ~/.sdirs

     escaped_path=${PWD/ /\\ }
     echo "export DIR_$1=$escaped_path" >> ~/.sdirs
  }

  # jump to bookmark
  function g {
     source ~/.sdirs
     path=$(eval $(echo echo $(echo \$DIR_$1)))
  
     # replace whitespaces with "\ " for escaping
     escaped_path=${path/ /\\ }
     cd_eval="cd $escaped_path"
    
     eval $cd_eval
  }
Hope this helps you guys like it helped me. And if there is a way to do this in an more elegant way, please let me know. This would help me to improve my none existing bash skills :D

Edit: I opened up a fork and commited all my changes to this repo. I also opened a pull request and I hope my fix will get accepted.

GitHub fork: https://github.com/Oemera/bashmarks

Thanks

Ă–mer