Coder Social home page Coder Social logo

smartcd's People

Contributors

blueyed avatar cxreg avatar daotoad avatar dohse avatar f0rk avatar gitter-badger avatar hd2fik avatar jlarky avatar jonasbn avatar mmlb avatar mpapis avatar mvgrimes avatar nstcactus avatar robjens avatar simonweil avatar toilal avatar xaocon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

smartcd's Issues

Trail of 0s after editing

After editing a script with 'smartcd edit enter' or 'smartcd edit leave', the terminal starts to output 0s!
Zero, newline, zero, newline, never stopping... I must CTRL^C out of it, and changes to the script are not saved.
I'm running Ubuntu 13.10 and zsh with the last oh-my-zsh version.

"smartcd reenter" executes "enter" twice with zsh's chpwd hook

I've noticed that smartcd reenter will cause the bash_enter script to be run twice.

This appears to be specific to the chpwd method, and does not happen with the following setup:

# smartcd setup chpwd-hook
smartcd setup cd
smartcd setup pushd
smartcd setup popd

Performance problems on Windows 10's Windows Subsystem for Linux

I suspect this is not something that can feasibly be fixed, however I figured I'd better report it anyway.

After installing smartcd in my Windows Subsystem for Linux (the Ubuntu 16.04 LTS flavor), changing directories—even ones without "enter" scripts—began taking multiple seconds to complete. Before installing smartcd, and after uninstalling smartcd, changing directories takes somewhere between a tenth of a second and half a second.

I believe it is a known shortcoming with WSL that filesystem actions can take significantly longer than what you'd expect, if for no other reason than NTFS is frequently not optimized for the same kinds of activities that Linux filesystems are. However, I suspect in this case the problem is more due to inefficiencies in WSL's bash—possibly in the implementation of functions?—than any filesystem/hardware shenanigans.

For now I've uninstalled the tool rather than look into it further. If you want me to help debug I'm willing, but if you're inclined to "will not fix" this I'd understand that as well.

.bashrc prompt ignored

with the following in the .smartcd_config:

smartcd setup prompt-hook

When opening creating a new session, the original prompt is replaced; ignoring my PROMPT_COMMAND.

I'd like that to be used till I override it for a specific directory.

smartcd + zsh on OS X leads to fork bomb and coredump

I haven't been able to track this down any further than I detail below; reporting this mainly in the hopes that somebody will point out I'm doing something stupid.

I'm loading smartcd here - https://github.com/genehack/etc/blob/master/zshrc#L113

The smartcd_config file is here - https://github.com/genehack/etc/blob/master/smartcd_config

With those two files, as they stand, I get a 'zsh quit unexpectedly' report every time I open a new shell. From the stack trace, zsh is going into some sort of recursive forkbomb until it hits some limit. (I'll attach that report as a comment on this report.)

Commenting out line 113 in .zshrc prevents this, as does commenting out line 3 in smartcd_config -- but this obviously also prevents smartcd from loading properly.

Any help is appreciated.

Trying to autostash function definitions produces odd output on changing directory

Attempting to autostash a function in an enter script results in the function being run for every other entry in the file. With the following enter script:

autostash npm() { echo "This is the backend"; echo "npm $@" }
autostash alias rails='docker-compose exec backend rails'
autostash alias rake='docker-compose exec backend rake'

this is output on changing into the directory:

This is the backend
npm smartcd_ondescend_callbacks
This is the backend
npm alias rails=docker-compose exec backend rails
This is the backend
npm alias rake=docker-compose exec backend rake

Placing the npm() function at the end of the file makes no difference to the output.

I don't want to use an alias here as it will output all the parameters passed to npm after the error message, which isn't a great look.

Does autostash work with functions? I ended up defining the function without using autostash in the enter script, and using disable -f npm in the leave script, but it would be really useful to be able to use autostash here…

(I'm using zsh, BTW…)

Question on new tabs and smartcd

I am using smartcd in combination with liquid prompt and it works like a charm, one thing I have not been able to figure out is how to enable smartcd for new tabs.

I am not doing anything fancy, I just like to prefix the prompts in some of my working directories using liquid prompt's prompt_tag

prompt_tag "\e[1;7m SUPERPROJECT \e[m"

What I currently am observing for new tabs is the following:

smartcd: running /Users/jonasbn/.smartcd/scripts/Users/jonasbn/develop/git-dkhm/project/bash_enter -bash: prompt_tag: command not found

Have anybody solved the issue with new tabs of have any pointers before I did into the smartcd source code.

Liquid Prompt: https://github.com/nojhan/liquidprompt

Overriding the `cd` function

Just installed smartcd on OS X using ZSH and installing smartcd has led to my cd function being changed:

> which cd         
cd () {
    smartcd cd "$@"
}

However, I usually use my own custom cd function:

cd () {
  builtin cd "$*"
  ls
}

Is there a way I can keep my custom behaviour but add smartcd to it as well?

Many thanks,

Jack

Customize location and respect XDG directories?

Hi, I like to organize all my dotfiles outside of my home directory and split up application data from user configuration. The XDG directories help do that - scripts would probably be under XDG_CONFIG_HOME, while the other application stuff would be under XDG_DATA_HOME and any caches would be under XDG_CACHE_HOME.

It would also be good to allow a user to set a simple environment variable to move the entire directory somewhere else... that's a simpler thing than splitting stuff up. Something like SMARTCD_HOME.

In this case, I used this to get my configuration (scripts) into my dotfiles:

rm -rf .smartcd/scripts
ln -s ~/dotfiles/config/smartcd/scripts ~/.smartcd/scripts

I would prefer to set an environment variable to avoid doing that.

Would you be open to a PR?

virtualenv helper doesn't deactivate properly on leave

The virtualenv helper doesn't evaluate the output of run_deactivate_if_present() when leaving (src)

               eval run_deactivate_if_present
               smartcd on-leave run_deactivate_if_present

This results in smartcd just printing the shell code instead of deactivating the virtualenv:

❯ cd
[ "`type -w deactivate`" = "function" ] && deactivate

Export is broken for more than just one directory

Ok, this is really easy to produce, but beyond me to figure out what's wrong. This works to repro bug:

 rm ~/.smartcd* -rf
 rm ~/.zshrc
 touch ~/.zshrc
 # choose defaults
 curl -L http://smartcd.org/install | bash
 source ~/.zshrc
 cd ~
 echo "echo 1" | smartcd edit enter
 cd ~/tmp
 echo "echo 1" | smartcd edit enter
 smartcd export

how do you source env variables from a different file in 'enter' script?

in the 'enter' script I am sourcing a file to load directory specific environment variables instead of directly adding the variables directly to the 'enter' script, but this does not work for me. any suggestions.

I'm my enter file:

setopt aliases
[[ -f __PATH__/boot.sh ]] && __PATH__/boot.sh

Hide "smartcd: running..." when changing directories

Currently, when changing directories, I get a message like this:

smartcd: running /Users/BenjaminLee/.smartcd/scripts/Users/BenjaminLee/Python/bash_leave

This can be annoying, especially since it's deactivating a virtualenv which already shows that it was deactivated. It there a way to suppress the notification?

"source" detection in load_smartcd does not work with zsh

c8356e9 was meant to fix it, but it does not work.

When sourcing it from zsh, I get:

% source load_smartcd
+load_smartcd:3> [[ -n 5.0.6-dev-0 ]]
+load_smartcd:4> [[ '' != load_smartcd ]]
+load_smartcd:5> echo 'This cannot be run as a command, please run'
This cannot be run as a command, please run
+load_smartcd:6> echo

+load_smartcd:7> echo '    source load_smartcd'
    source load_smartcd
+load_smartcd:8> exit 1

Maybe this was just taken from http://unix.stackexchange.com/a/73010/1920, or have you tested it?

download-installer does not fail on lwp error

after running curl -L http://smartcd.org/install | bash:

$ cat /home/mpapis/.smartcd/lib/core/smartcd
LWP will support https URLs if the LWP::Protocol::https module
is installed.
$ lwp-request https://raw.github.com/cxreg/smartcd/master/lib/core/smartcd
LWP will support https URLs if the LWP::Protocol::https module
is installed.
$ echo $?
1

curl has proven to work more reliable across different systems, maybe it should be moved to be the first validated option ?

History helper documentation

Before smartcd my system was setup to keep a history per directory. The documentation hints for a similar functionality but is confusing me at best.

add support for chpwd_functions

following rvm/rvm#2819 - explicit support for smartcd was removed from RVM and replaced with generic handler chpwd_functions implemented in accordance to Zsh specification => http://zsh.sourceforge.net/Doc/Release/Functions.html#Hook-Functions

you can implement the same mechanism using this code:

  [[ -n "${ZSH_VERSION:-}" ]] ||
  {
    # On bash and old zsh we need to define chpwd_functions handler
    __zsh_like_cd()
    {
      typeset __zsh_like_cd_hook
      if
        builtin "$@"
      then
        shift || true # remove the called method
        for __zsh_like_cd_hook in chpwd "${chpwd_functions[@]}"
        do
          if typeset -v "$__zsh_like_cd_hook" >/dev/null 2>&1
          then "$__zsh_like_cd_hook" "$@" || break # finish on first failed hook
          fi
        done
        true
      else
        return $?
      fi
    }
    cd()    { __zsh_like_cd cd    "$@" ; }
    popd()  { __zsh_like_cd popd  "$@" ; }
    pushd() { __zsh_like_cd pushd "$@" ; }
  }

from now on adding code to execute after cd is as easy as:

export -a chpwd_functions
chpwd_functions=( "${chpwd_functions[@]}" smartcd )

and this will be compatible with all other software implementing the same mechanism

Backticks in autostash alias

Hi - any thoughts on how the following can be made to work?

Using templates, I want to autostash an alias that includes backticks. I don't want the backticks to be evaluated; they are unfortunately a requirement in a MySQL command to surround a database name that contains a dash (-):

autostash alias dump_staging='"mysql" -e "drop database if exists `$DATABASE`"'

Test failures (especially with bash)

I am seeing a few test failures with make test_bash.

The first one ("35 - autoedit seems to work") also happens with zsh.

t/harness.sh /bin/bash
Testing with SHELL=/bin/bash
1..19
ok 1 - created 3 element array
ok 2 - extended array by one quoted element
ok 3 - quoted element is in-tact
ok 4 - unshift extended array
ok 5 - unshift put element at beginning of array
ok 6 - quoted element is still last and still in-tact
ok 7 - array shrunk by one element from pop
ok 8 - got correct element from pop
ok 9 - array shrunk by one element from shift
ok 10 - got correct element from shift
ok 11 - array reversed, last is now first
ok 12 - array reversed, first is now last
ok 13 - copied array
ok 14 - array detected
ok 15 - non-array detected
ok 16 - afirst works with element with double-space
ok 17 - alast works with element with double-space
ok 18 - apop works with element with double-space
ok 19 - ashift works with element with double-space
1..36
ok 1 - manual stash warned
ok 2 - stashed variable
ok 3 - manual unstash warned
ok 4 - unstashed variable successfully
ok 5 - stash variable unset
ok 6 - unexported on unstash
ok 7 - double unstash did not delete value
ok 8 - manual autostash warned
ok 9 - autounstashed variable successfully
ok 10 - stash variable unset
ok 11 - autostash variable unset
ok 12 - quieted warning
ok 13 - double stash warns
ok 14 - did not double stash without force
ok 15 - force double stash does not warn
ok 16 - double stashed with force
ok 17 - double stash assign without force worked
ok 18 - stashed unset variable
ok 19 - stash-assigned value
ok 20 - could unstash from stash-assignment
ok 21 - autostash-assigned value
ok 22 - could unstash from autostash-assignment
ok 23 - stash-assigned previously unset variable
ok 24 - unset previously unset variable on unstash
ok 25 - autostash-assigned previously unset variable
ok 26 - unset previously unset variable on autounstash
ok 27 - could stash-assign complex quoted expression
ok 28 - variable exported on unstash
ok 29 - unstashed alias
ok 30 - unstashed function at the same time as alias
ok 31 - unstashed array
ok 32 - created smartcd file
ok 33 - correctly configured autostash
ok 34 - restored variable
not ok 35 - autoedit seems to work
#   Failed test 'autoedit seems to work'
#   in t/tap-functions:is() at line 290.
#          got: '########################################################################
# smartcd bash_enter - /home/user/.dotfiles/smartcd
#
# This is a smartcd script.  Commands you type will be run when you
# bash_enter this directory.  The string __PATH__ will be replaced with
# the current path.
#
# See http://smartcd.org for more ideas about what can be put here
########################################################################'
#     expected: 'autostash RANDOM_VARIABLE'
ok 36 - restored $HOME
# Looks like you failed 1 test of 36.
1..13
ok 1 - smartcd informed user of script execution
ok 2 - quieted output
ok 3 - bash_enter executed successfully using smartcd
ok 4 - bash_enter executed successfully using smartcd pushd
ok 5 - bash_leave executed successfully using smartcd
ok 6 - bash_leave executed successfully using smartcd popd
ok 7 - cd -P still works
lib/core/smartcd: line 317: $file: ambiguous redirect
lib/core/smartcd: line 339: $base/inodes$dir.inode: ambiguous redirect
not ok 8 - could enter and leave a directory with a space
#   Failed test 'could enter and leave a directory with a space'
#   in t/tap-functions:is() at line 290.
#          got: 'WARNING!  Possibly outdated scripts detected, not running them.  These
scripts were created for a directory which has been deleted or replaced,
but the scripts for them remained.  Please check the following files
for correctness:

    /home/user/.dotfiles/smartcd/tmphome/.smartcd/scripts/home/user/.dotfiles/smartcd/dir with a space/bash_enter
    /home/user/.dotfiles/smartcd/tmphome/.smartcd/scripts/home/user/.dotfiles/smartcd/dir with a space/bash_leave

Once you have verified or corrected the situation, remove the following
file to make this warning go away

    /home/user/.dotfiles/smartcd/tmphome/.smartcd/inodes/home/user/.dotfiles/smartcd/dir with a space.inode

If you don't wish to keep this safety check in place, set SMARTCD_NO_INODE=1
or re-run `smartcd config`

To permanently ignore this check only for /home/user/.dotfiles/smartcd/dir with a space, run the following command

    echo '*' > "/home/user/.dotfiles/smartcd/tmphome/.smartcd/inodes/home/user/.dotfiles/smartcd/dir with a space.inode"'
#     expected: '1 2'
lib/core/smartcd: line 339: $base/inodes$dir.inode: ambiguous redirect
lib/core/smartcd: line 317: $file: ambiguous redirect
lib/core/smartcd: line 339: $base/inodes$dir.inode: ambiguous redirect
lib/core/smartcd: line 339: $base/inodes$dir.inode: ambiguous redirect
not ok 9 - could enter and leave a subdirectory of a directory with a space
#   Failed test 'could enter and leave a subdirectory of a directory with a space'
#   in t/tap-functions:is() at line 290.
#          got: 'WARNING!  Possibly outdated scripts detected, not running them.  These
scripts were created for a directory which has been deleted or replaced,
but the scripts for them remained.  Please check the following files
for correctness:

    /home/user/.dotfiles/smartcd/tmphome/.smartcd/scripts/home/user/.dotfiles/smartcd/dir with a space/bash_enter
    /home/user/.dotfiles/smartcd/tmphome/.smartcd/scripts/home/user/.dotfiles/smartcd/dir with a space/bash_leave

Once you have verified or corrected the situation, remove the following
file to make this warning go away

    /home/user/.dotfiles/smartcd/tmphome/.smartcd/inodes/home/user/.dotfiles/smartcd/dir with a space.inode

If you don't wish to keep this safety check in place, set SMARTCD_NO_INODE=1
or re-run `smartcd config`

To permanently ignore this check only for /home/user/.dotfiles/smartcd/dir with a space, run the following command

    echo '*' > "/home/user/.dotfiles/smartcd/tmphome/.smartcd/inodes/home/user/.dotfiles/smartcd/dir with a space.inode"
WARNING!  Possibly outdated scripts detected, not running them.  These
scripts were created for a directory which has been deleted or replaced,
but the scripts for them remained.  Please check the following files
for correctness:

    /home/user/.dotfiles/smartcd/tmphome/.smartcd/scripts/home/user/.dotfiles/smartcd/dir with a space/subdir/bash_enter
    /home/user/.dotfiles/smartcd/tmphome/.smartcd/scripts/home/user/.dotfiles/smartcd/dir with a space/subdir/bash_leave

Once you have verified or corrected the situation, remove the following
file to make this warning go away

    /home/user/.dotfiles/smartcd/tmphome/.smartcd/inodes/home/user/.dotfiles/smartcd/dir with a space/subdir.inode

If you don't wish to keep this safety check in place, set SMARTCD_NO_INODE=1
or re-run `smartcd config`

To permanently ignore this check only for /home/user/.dotfiles/smartcd/dir with a space/subdir, run the following command

    echo '*' > "/home/user/.dotfiles/smartcd/tmphome/.smartcd/inodes/home/user/.dotfiles/smartcd/dir with a space/subdir.inode"
WARNING!  Possibly outdated scripts detected, not running them.  These
scripts were created for a directory which has been deleted or replaced,
but the scripts for them remained.  Please check the following files
for correctness:

    /home/user/.dotfiles/smartcd/tmphome/.smartcd/scripts/home/user/.dotfiles/smartcd/dir with a space/bash_enter
    /home/user/.dotfiles/smartcd/tmphome/.smartcd/scripts/home/user/.dotfiles/smartcd/dir with a space/bash_leave

Once you have verified or corrected the situation, remove the following
file to make this warning go away

    /home/user/.dotfiles/smartcd/tmphome/.smartcd/inodes/home/user/.dotfiles/smartcd/dir with a space.inode

If you don't wish to keep this safety check in place, set SMARTCD_NO_INODE=1
or re-run `smartcd config`

To permanently ignore this check only for /home/user/.dotfiles/smartcd/dir with a space, run the following command

    echo '*' > "/home/user/.dotfiles/smartcd/tmphome/.smartcd/inodes/home/user/.dotfiles/smartcd/dir with a space.inode"'
#     expected: '1 2 3 4'
ok 10 - ran two bash_enter scripts in correct order
ok 11 - ran two bash_leave scripts in correct order
ok 12 - smartcd doesn't try to re-enter a deleted directory
ok 13 - not running zsh, no chpwd-hook
# Looks like you failed 2 tests of 13.
make: *** [test_bash] Error 2

Add smartcd to homebrew

Hi,

Firstly, thank you for a great and useful project - it really helps me in my day to day work!

I requested to add smartcd to homebrew, the package manager for OSX.

They replied that they require version release tagging in order to add smartcd to homebrew.

Would it be possible to do so? homebrew is very helpful for managing software on OSX (I use it for almost all my install software) and I'm sure smartcd will benefit from being on homebrew too by being more widely exposed.

You can view the issue here: Homebrew/legacy-homebrew#28473

Problems when autostash alias override existing .bashrc defined alias

Place the following in your .bashrc:

alias hello='echo "hello world"'

Then setup an enter script for any directory containing the following:

autostash alias hello='echo "hello gophers"'

Then cd into that directory, you will see the following error:

$ cd -
/home/myitcv/blah
smartcd: running /home/myitcv/.smartcd/scripts/home/myitcv/blah/bash_enter

Command 'world'' not found, did you mean:

  command 'world' from snap world (4.0)

See 'snap info <snapname>' for additional versions.

Why is .bash_enter and .bash_leave deprecated?

Hi,

I've just installed smartcd and by the first look it looks like an excellent work. I have one question though: what is the reason for deprecating .bash_enter and .bash_leave?

I agree that it is nice to have out-of-directory control of smartcd, but in-directory is nice too. In my case I would like to commit the .bash_enter to version control so other project members can benefit from getting PATH settings automatically.

bash_enter run twice on smartcd load if $PWD ends in a slash

If $PWD ends in a slash, I'm seeing bash_enter run twice, the second time with two slashes between the directory path and bash_enter. E.g. the following is from a new shell starting in a tmux pane with the initial path being /Users/von/.local/share/chezmoi/:

DEBUG: PWD=/Users/von/.local/share/chezmoi/
DEBUG: source smartcd
smartcd: running /Users/von/.smartcd/scripts/Users/von/.local/share/chezmoi/bash_enter
Setting up chezmoi environment.
smartcd: running /Users/von/.smartcd/scripts/Users/von/.local/share/chezmoi//bash_enter
Setting up chezmoi environment.
DEBUG: source smartcd done

If I trim the slash from the end of $PWD (PWD=${PWD%/}), the double execution goes away:

DEBUG: PWD=/Users/von/.local/share/chezmoi
DEBUG: source smartcd
smartcd: running /Users/von/.smartcd/scripts/Users/von/.local/share/chezmoi/bash_enter
Setting up chezmoi environment.
DEBUG: source smartcd done

Not sure what version of smartcd I'm running as I can't find any sort of version command.

symlink bypasses bash_enter

hey dave :)

i came across an issue. steps to reproduce:

  • create a symlink from outside a directory hierarchy observed by smartcd, to some directories into that hierarchy.
    eg: ln -s dir_with_env_set_by_smart_cd/one_dir_in/second_dir_in second_level
  • cd into it using the symlink
    eg: cd second level

Result:
though I end up at the right destination, the system variables from bash_enter are not being set

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.