diff options
| author | Eugene Triguba <hello@eugenetriguba.com> | 2025-10-25 10:27:06 -0400 |
|---|---|---|
| committer | Eugene Triguba <hello@eugenetriguba.com> | 2025-10-25 10:43:02 -0400 |
| commit | 7837a88380da6057b81d1f741d39a79bc83993c0 (patch) | |
| tree | e954d6057c8c5866a0e401b88b152067c4c5880e | |
| parent | Add ability to use prefix key with key bindings (diff) | |
| download | tmux-toggle-term-7837a88380da6057b81d1f741d39a79bc83993c0.zip | |
Add ability to disable float or split functionalityv0.4.0
| -rw-r--r-- | CHANGELOG.md | 7 | ||||
| -rw-r--r-- | README.md | 12 | ||||
| -rwxr-xr-x | plugin.tmux | 34 | ||||
| -rw-r--r-- | tests/tests.sh | 93 |
4 files changed, 136 insertions, 10 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index ecf2b71..58fcbb8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.4.0] - 2025-10-25 + +### Added + +- Ability to disable float or split functionality individually using + `@toggle-term-float-enabled` and `@toggle-term-split-enabled` options. + ## [0.3.0] - 2025-08-17 ### Added @@ -28,6 +28,18 @@ Reload tmux and press prefix + I to install. ## Customization +### Disabling Features + +By default, both the floating and split terminal features are enabled. If you only want one of them, you can disable the other: + +```tmux +# Disable the floating terminal (only use split) +set -g @toggle-term-float-enabled 'false' + +# Disable the split terminal (only use floating) +set -g @toggle-term-split-enabled 'false' +``` + ### Custom Key Bindings You can override the default keybindings by setting the diff --git a/plugin.tmux b/plugin.tmux index 32ff62e..43d587a 100755 --- a/plugin.tmux +++ b/plugin.tmux @@ -10,26 +10,32 @@ SCRIPTS_DIR="${CURRENT_DIR}/scripts" FLOAT_KEYBINDING="C-f" FLOAT_KEYBINDING_OPTION="@toggle-term-float-key" FLOAT_USE_PREFIX_OPTION="@toggle-term-float-use-prefix" +FLOAT_ENABLED_OPTION="@toggle-term-float-enabled" SPLIT_KEYBINDING="C-\;" SPLIT_KEYBINDING_OPTION="@toggle-term-split-key" SPLIT_USE_PREFIX_OPTION="@toggle-term-split-use-prefix" +SPLIT_ENABLED_OPTION="@toggle-term-split-enabled" main() { tmux_cmd="$(get_tmux_cmd)" - float_key_binding="$(float_key)" - if [ "$(use_prefix_for_float)" = "true" ]; then - $tmux_cmd bind-key "$float_key_binding" run-shell -b "$SCRIPTS_DIR/toggle-term.sh float" - else - $tmux_cmd bind-key -n "$float_key_binding" run-shell -b "$SCRIPTS_DIR/toggle-term.sh float" + if [ "$(float_enabled)" = "true" ]; then + float_key_binding="$(float_key)" + if [ "$(use_prefix_for_float)" = "true" ]; then + $tmux_cmd bind-key "$float_key_binding" run-shell -b "$SCRIPTS_DIR/toggle-term.sh float" + else + $tmux_cmd bind-key -n "$float_key_binding" run-shell -b "$SCRIPTS_DIR/toggle-term.sh float" + fi fi - split_key_binding="$(split_key)" - if [ "$(use_prefix_for_split)" = "true" ]; then - $tmux_cmd bind-key "$split_key_binding" run-shell -b "$SCRIPTS_DIR/toggle-term.sh split" - else - $tmux_cmd bind-key -n "$split_key_binding" run-shell -b "$SCRIPTS_DIR/toggle-term.sh split" + if [ "$(split_enabled)" = "true" ]; then + split_key_binding="$(split_key)" + if [ "$(use_prefix_for_split)" = "true" ]; then + $tmux_cmd bind-key "$split_key_binding" run-shell -b "$SCRIPTS_DIR/toggle-term.sh split" + else + $tmux_cmd bind-key -n "$split_key_binding" run-shell -b "$SCRIPTS_DIR/toggle-term.sh split" + fi fi } @@ -49,6 +55,14 @@ use_prefix_for_split() { get_tmux_option "$SPLIT_USE_PREFIX_OPTION" "false" } +float_enabled() { + get_tmux_option "$FLOAT_ENABLED_OPTION" "true" +} + +split_enabled() { + get_tmux_option "$SPLIT_ENABLED_OPTION" "true" +} + get_tmux_option() { option="$1" default_value="$2" diff --git a/tests/tests.sh b/tests/tests.sh index bf9204e..88e34aa 100644 --- a/tests/tests.sh +++ b/tests/tests.sh @@ -185,3 +185,96 @@ load_plugin() { run tmux_has_prefix_binding "C-;" "split" assert_failure } + +@test 'both float and split are enabled by default' { + run load_plugin + assert_success + + run tmux_has_root_binding "C-f" "float" + assert_success + run tmux_has_root_binding "C-;" "split" + assert_success +} + +@test 'float can be disabled' { + tmux_set_option "@toggle-term-float-enabled" "false" + + run load_plugin + assert_success + + run tmux_has_root_binding "C-f" "float" + assert_failure + run tmux_has_root_binding "C-;" "split" + assert_success +} + +@test 'split can be disabled' { + tmux_set_option "@toggle-term-split-enabled" "false" + + run load_plugin + assert_success + + run tmux_has_root_binding "C-f" "float" + assert_success + run tmux_has_root_binding "C-;" "split" + assert_failure +} + +@test 'both float and split can be disabled' { + tmux_set_option "@toggle-term-float-enabled" "false" + tmux_set_option "@toggle-term-split-enabled" "false" + + run load_plugin + assert_success + + run tmux_has_root_binding "C-f" "float" + assert_failure + run tmux_has_root_binding "C-;" "split" + assert_failure +} + +@test 'disabled float does not bind with custom key' { + tmux_set_option "@toggle-term-float-enabled" "false" + tmux_set_option "@toggle-term-float-key" "M-f" + + run load_plugin + assert_success + + run tmux_has_root_binding "M-f" "float" + assert_failure +} + +@test 'disabled split does not bind with custom key' { + tmux_set_option "@toggle-term-split-enabled" "false" + tmux_set_option "@toggle-term-split-key" "M-t" + + run load_plugin + assert_success + + run tmux_has_root_binding "M-t" "split" + assert_failure +} + +@test 'disabled float does not bind with prefix' { + tmux_set_option "@toggle-term-float-enabled" "false" + tmux_set_option "@toggle-term-float-key" "f" + tmux_set_option "@toggle-term-float-use-prefix" "true" + + run load_plugin + assert_success + + run tmux_has_prefix_binding "f" "float" + assert_failure +} + +@test 'disabled split does not bind with prefix' { + tmux_set_option "@toggle-term-split-enabled" "false" + tmux_set_option "@toggle-term-split-key" "f" + tmux_set_option "@toggle-term-split-use-prefix" "true" + + run load_plugin + assert_success + + run tmux_has_prefix_binding "f" "split" + assert_failure +} |