Skip to content

Commit

Permalink
auto-activation through zshrc
Browse files Browse the repository at this point in the history
  • Loading branch information
irth committed Dec 17, 2022
1 parent 8b30ed5 commit 488d1a3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ https://gist.github.com/irth/ffba9da0a9a4f6df54f02fe06605f19c
- [x] communicate over a unix socket, path to which is passed through an env variable (so that u can have more than one shell)
- [x] generate config for zsh, so that it can be eval'ed in .zshrc easily
- [x] limit the saved buffer size so that it doesn't fill up your ram (for now I hardcoded it to 32MiB)
- [ ] allow auto-activation through zshrc
- [x] allow auto-activation through zshrc

### v2

Expand Down
39 changes: 23 additions & 16 deletions init.zsh
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
_kacpersh_start() {
curl -s --unix-socket "$KACPERSH_SOCK" http://kacpersh/start
}
_kacpersh_stop() {
curl -s --unix-socket "$KACPERSH_SOCK" http://kacpersh/stop
}
if [[ $- == *i* ]]; then
if [[ -z "$KACPERSH_SOCK" ]]; then
# we're not running in kacpersh. Reexecute.
exec kacpersh
fi
# only run if shell is interactive
_kacpersh_start() {
curl -s --unix-socket "$KACPERSH_SOCK" http://kacpersh/start
}
_kacpersh_stop() {
curl -s --unix-socket "$KACPERSH_SOCK" http://kacpersh/stop
}

if [[ "$KACPERSH_CUSTOM_HOOKS" != "1" ]] && [[ -n "$KACPERSH_SOCK" ]]; then
autoload add-zsh-hook
add-zsh-hook precmd _kacpersh_stop
add-zsh-hook preexec _kacpersh_start
if [[ "$KACPERSH_CUSTOM_HOOKS" != "1" ]] && [[ -n "$KACPERSH_SOCK" ]]; then
autoload add-zsh-hook
add-zsh-hook precmd _kacpersh_stop
add-zsh-hook preexec _kacpersh_start

kacpersh_last() {
if [[ -n "$KACPERSH_SOCK" ]]; then
curl -s --output - --unix-socket "$KACPERSH_SOCK" http://kacpersh/last
fi
}
kacpersh_last() {
if [[ -n "$KACPERSH_SOCK" ]]; then
curl -s --output - --unix-socket "$KACPERSH_SOCK" http://kacpersh/last
fi
}

alias _=kacpersh_last
alias _=kacpersh_last
fi
fi

0 comments on commit 488d1a3

Please sign in to comment.