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

Ability to execute commands when entering/leaving a project #31

Open
ngirard opened this issue Feb 16, 2021 · 2 comments
Open

Ability to execute commands when entering/leaving a project #31

ngirard opened this issue Feb 16, 2021 · 2 comments

Comments

@ngirard
Copy link

ngirard commented Feb 16, 2021

I'm enthusiastic about Sauce, having struggled with similar needs for long myself. I came up with some unreleased code, which allows me to cover a subset of what Sauce currently offers.

One feature I find it useful, is the ability to execute commands whenever I start working on a project, and whenever I stop working on it.

It'd be great if Sauce could feature this, especially with it's cascading loading capabilities !

FWIW, here's the gist of my Bash code that implements this:

[[ -n $WSDIR ]] && {
    export HISTFILE="$WSDIR/history"
    history -c ; history -r
    [[ ! -d "$WSDIR" ]] && mkdir "$WSDIR"
    cd "$WSDIR"
    start_shell_in_workspace_hook
    hookfile="$WSDIR/.workspace_hook_run"
    [[ -f "$hookfile" ]] || {
        touch "$hookfile"
        trap stop_workspace_hook EXIT
        start_workspace_hook
    }
}

and my stop_workspace_hook() function consists in:

stop_workspace_hook(){
    rm "$hookfile"
    ....
}
@DanCardin
Copy link
Owner

I wrote sauce in rust precisely because I dont feel like I understand shell code well enough to write it in bash, so it's not entirely obvious to me what exactly you're doing above :p.

If I understand the gist of the request though, I'm likely into the idea of adding some sort of in-built ability to run arbitrary shell-code upon sauce (automatically on enter, with autoload=true), and once you've supported on-enter, on-exit probably also makes sense.

@DanCardin
Copy link
Owner

DanCardin commented Jun 21, 2021

I have a simple/sample implementation of "on enter" functionality. This is very straightforward, and uses essentially identical semantics to normal cascade behavior.

It's when thinking about the "on exit" behavior that questions start coming up.

Should on-exit only run for the previous $PWD? Should it run for all parent directories? Should it only run for the diff between the prev/current pwd (~/foo/bar/baz -> ~/foo runs ~/foo/bar/baz then ~/foo/bar on-exit)?

It kind of seems like the last one is what one would expect, and would then follow that my impl of on-enter is flawed and should only run for the diff between the prev/current dirs also.

and the trap behavior for EXIT is probably a natural extension where the "current" set is empty and prev - current would thereby yield all dirs

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