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

Plugins: tmux, goenv, pyenv #266

Merged
merged 11 commits into from
Dec 24, 2021
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
*.swp
*.disabled
.idea/
*.tmp
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ For example, this line might begin to look like this:
plugins=(git bundler osx rake ruby)
```

##### With Conditionals

You may want to control when and/or how plugins should be enabled.

For example, if you want the `tmux-autoattach` plugin to only run on SSH sessions, you could employ a trivial conditional that checks for the `$SSH_TTY` variable. Just make sure to remove the plugin from the larger plugin list.

``` bash
[ "$SSH_TTY" ] && plugins+=(tmux-autoattach)
```

chopnico marked this conversation as resolved.
Show resolved Hide resolved
#### Using Plugins

Most plugins (should! we're working on this) include a __README__, which documents how to use them.
Expand Down
3 changes: 3 additions & 0 deletions plugins/goenv/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# goenv plugin

The goenv plugin will configure goenv paths and configure goenv to manage GOROOT and GOHOME.
14 changes: 14 additions & 0 deletions plugins/goenv/goenv.plugin.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# @chopnico 2021

if [ -d "$HOME/.goenv" ]; then
# goenv exported variables
export GOENV_ROOT="$HOME/.goenv"
export PATH="$GOENV_ROOT/bin:$PATH"

# Enables goenv shims
eval "$(goenv init -)"

# Allows goenv to manage GOPATH and GOROOT
export PATH="$GOROOT/bin:$PATH"
export PATH="$PATH:$GOPATH/bin"
fi
3 changes: 3 additions & 0 deletions plugins/pyenv/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# pyenv plugin

The pyenv plugin will configure pyenv paths.
8 changes: 8 additions & 0 deletions plugins/pyenv/pyenv.plugin.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# @chopnico 2021

if [ -d "$HOME/.pyenv" ]; then
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
fi
40 changes: 40 additions & 0 deletions plugins/tmux-autoattach/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# tmux-autoattach.plugin

This tmux plugin will automatically attach a tmux session to your shell session.

## Variables

#### OSH_PLUGIN_TMUX_AUTOATTACH_BEHAVIOR

| Setting | Description |
|--------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `detach` (default) | This will allow you to detach from the tmux screen without closing the terminal or shell session. |
| `exit` | This will completely close out your shell session, including your terminal, but keep your tmux sessions intact. This will also close your session if you detach. |

## Common Enable Conditions

*Note* If you prefer to manually start your desktop session using tools like `startx`, you may run into problems starting your desktop session inside of a tmux terminal. You can employ conditionals to control when this plugin should be enabled.

**SSH**

```bash
[ "$SSH_TTY" ] && plugins+=(tmux-autoattach)
```

**Wayland**

```bash
[ "$DISPLAY_WAYLAND" ] && plugins+=(tmux-autoattach)
```

**X11**

```bash
[ "$DISPLAY" ] && plugins+=(tmux-autoattach)
```

**Multiple**

```bash
{ [ "$DISPLAY" ] || [ "$SSH" ]; } && plugins+=(tmux-autoattach)
chopnico marked this conversation as resolved.
Show resolved Hide resolved
```
24 changes: 24 additions & 0 deletions plugins/tmux-autoattach/tmux-autoattach.plugin.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# @chopnico 2021
#
# tmux-autoattach.plugin.sh
#
# A tmux plugin that will automatically attach itself to a bash session.

[ -z "$OSH_PLUGIN_TMUX_AUTOATTACH_BEHAVIOR" ] && OSH_PLUGIN_TMUX_AUTOATTACH_BEHAVIOR="detach"

_osh_plugin_tmux_autoattach_exit() {
[ -z "$TMUX" ] && tmux -2u new -A && exit
}

_osh_plugin_tmux_autoattach_detach() {
[ -z "$TMUX" ] && tmux -2u new -A
}

case "$OSH_PLUGIN_TMUX_AUTOATTACH_BEHAVIOR" in
"exit")
_osh_plugin_tmux_autoattach_exit
;;
"detach" | *)
_osh_plugin_tmux_autoattach_detach
;;
esac