Skip to content

Commit

Permalink
Merge pull request #1 from gmatheu/feature_additional_configs
Browse files Browse the repository at this point in the history
Feature additional configs (porting PR omerxx#43)
  • Loading branch information
gmatheu authored Dec 12, 2024
2 parents 61c7f46 + 906b145 commit 7023ff0
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 22 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ set -g @floax-bind '-n M-p'
# Setting the main key to toggle the floating pane on and off
set -g @floax-bind '<my-key>'

# Setting the prefix key for quick actions in the floating pane (zoom in, zoom out, reset, lock, unlock, etc)
set -g @floax-prefix 'C-M'

# When the pane is toggled, using this bind pops a menu with additional options
# such as resize, fullscreen, resetting to defaults and more.
set -g @floax-bind-menu 'P'
Expand All @@ -60,6 +63,22 @@ set -g @floax-bind-menu 'P'
set -g @floax-width '80%'
set -g @floax-height '80%'

# The default location of the floating pane.
# Both may be a row or column number,
# or one of the following special values (from 'man tmux' or https://man.openbsd.org/OpenBSD-current/man1/tmux.1#display-menu):
# Value Flag Meaning
# C Both The centre of the terminal
# R -x The right side of the terminal
# P Both The bottom left of the pane
# M Both The mouse position
# W Both The window position on the status line
# S -y The line above or below the status line
For instance, to make it locate in the top-right
# set -g @floax-width 'R'
# set -g @floax-height '0'
set -g @floax-x 'C'
set -g @floax-y 'C'

# The border color can be changed, these are the colors supported by Tmux:
# black, red, green, yellow, blue, magenta, cyan, white for the standard
# terminal colors; brightred, brightyellow and so on for the bright variants;
Expand All @@ -84,9 +103,13 @@ set -g @floax-session-name 'some-other-session-name'

# Change the title of the floating window
set -g @floax-title 'floax'

# If you want to enable the status bar, you can set this to 'on'
set -g @floax-status-bar 'off'
```

## Known issues 🐞

- ~Sizing too much down will break the script~

## Contributors 🙌
Expand Down
10 changes: 7 additions & 3 deletions floax.tmux
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ source "$CURRENT_DIR/scripts/utils.sh"
tmux bind-key $(tmux_option_or_fallback "@floax-bind" "p") run-shell "$CURRENT_DIR/floax.sh"
tmux bind-key "$(tmux_option_or_fallback "@floax-bind-menu" "P")" run-shell "$CURRENT_DIR/menu.sh"

tmux setenv -g FLOAX_WIDTH "$(tmux_option_or_fallback '@floax-width' '80%')"
tmux setenv -g FLOAX_HEIGHT "$(tmux_option_or_fallback '@floax-height' '80%')"
tmux setenv -g FLOAX_WIDTH "$(tmux_option_or_fallback '@floax-width' '80%')"
tmux setenv -g FLOAX_HEIGHT "$(tmux_option_or_fallback '@floax-height' '80%')"
tmux setenv -g FLOAX_X "$(tmux_option_or_fallback '@floax-x' 'C')"
tmux setenv -g FLOAX_Y "$(tmux_option_or_fallback '@floax-y' 'C')"

# Options: black, red, green, yellow, blue, magenta, cyan, white
tmux setenv -g FLOAX_BORDER_COLOR "$(tmux_option_or_fallback '@floax-border-color' 'magenta')"
tmux setenv -g FLOAX_TEXT_COLOR "$(tmux_option_or_fallback '@floax-text-color' 'blue')"
tmux setenv -g FLOAX_TITLE "$(tmux_option_or_fallback '@floax-title' "${DEFAULT_TITLE}")"
tmux setenv -g FLOAX_CHANGE_PATH "$(tmux_option_or_fallback '@floax-change-path' 'true')"
tmux setenv -g FLOAX_CHANGE_PATH "$(tmux_option_or_fallback '@floax-change-path' 'true')"
tmux setenv -g FLOAX_PREFIX "$(tmux_option_or_fallback '@floax-prefix' 'C')"
tmux setenv -g FLOAX_STATUS_BAR "$(tmux_option_or_fallback '@floax-status-bar' 'off')"
tmux setenv -g FLOAX_SESSION_NAME "$(tmux_option_or_fallback '@floax-session-name' "${DEFAULT_SESSION_NAME}")"

eval "$(tmux showenv -s)"
3 changes: 2 additions & 1 deletion scripts/floax.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$CURRENT_DIR/utils.sh"
FLOAX_STATUS_BAR=$(envvar_value FLOAX_STATUS_BAR)

tmux setenv -g ORIGIN_SESSION "$(tmux display -p '#{session_name}')"
if [ "$(tmux display-message -p '#{session_name}')" = "$FLOAX_SESSION_NAME" ]; then
Expand All @@ -26,7 +27,7 @@ else
else
# Create a new session named 'scratch' and attach to it
tmux new-session -d -c "$(tmux display-message -p '#{pane_current_path}')" -s "$FLOAX_SESSION_NAME"
tmux set-option -t "$FLOAX_SESSION_NAME" status off
tmux set-option -t "$FLOAX_SESSION_NAME" status "${FLOAX_STATUS_BAR}"
tmux_popup
fi
fi
37 changes: 21 additions & 16 deletions scripts/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,37 @@ tmux_option_or_fallback() {
}

FLOAX_WIDTH=$(envvar_value FLOAX_WIDTH)
FLOAX_X=$(envvar_value FLOAX_X)
FLOAX_Y=$(envvar_value FLOAX_Y)
FLOAX_HEIGHT=$(envvar_value FLOAX_HEIGHT)
FLOAX_BORDER_COLOR=$(envvar_value FLOAX_BORDER_COLOR)
FLOAX_TEXT_COLOR=$(envvar_value FLOAX_TEXT_COLOR)
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
FLOAX_CHANGE_PATH=$(envvar_value FLOAX_CHANGE_PATH)
FLOAX_PREFIX=$(envvar_value FLOAX_PREFIX)
FLOAX_TITLE=$(envvar_value FLOAX_TITLE)
DEFAULT_TITLE='FloaX: C-M-s 󰘕  C-M-b 󰁌  C-M-f 󰊓  C-M-r 󰑓  C-M-e 󱂬  C-M-d '
DEFAULT_TITLE="FloaX: ${FLOAX_PREFIX}-s 󰘕  ${FLOAX_PREFIX}-b 󰁌  ${FLOAX_PREFIX}-f 󰊓  ${FLOAX_PREFIX}-r 󰑓  ${FLOAX_PREFIX}-e 󱂬  ${FLOAX_PREFIX}-d "
FLOAX_SESSION_NAME=$(envvar_value FLOAX_SESSION_NAME)
DEFAULT_SESSION_NAME='scratch'

set_bindings() {
tmux bind -n C-M-s run "$CURRENT_DIR/zoom-options.sh in"
tmux bind -n c-M-b run "$CURRENT_DIR/zoom-options.sh out"
tmux bind -n C-M-f run "$CURRENT_DIR/zoom-options.sh full"
tmux bind -n C-M-r run "$CURRENT_DIR/zoom-options.sh reset"
tmux bind -n C-M-e run "$CURRENT_DIR/embed.sh embed"
tmux bind -n C-M-d run "$CURRENT_DIR/zoom-options.sh lock"
tmux bind -n C-M-u run "$CURRENT_DIR/zoom-options.sh unlock"
tmux bind -n "${FLOAX_PREFIX}-s" run "$CURRENT_DIR/zoom-options.sh in"
tmux bind -n "${FLOAX_PREFIX}-b" run "$CURRENT_DIR/zoom-options.sh out"
tmux bind -n "${FLOAX_PREFIX}-f" run "$CURRENT_DIR/zoom-options.sh full"
tmux bind -n "${FLOAX_PREFIX}-r" run "$CURRENT_DIR/zoom-options.sh reset"
tmux bind -n "${FLOAX_PREFIX}-e" run "$CURRENT_DIR/embed.sh embed"
tmux bind -n "${FLOAX_PREFIX}-d" run "$CURRENT_DIR/zoom-options.sh lock"
tmux bind -n "${FLOAX_PREFIX}-u" run "$CURRENT_DIR/zoom-options.sh unlock"
}

unset_bindings() {
tmux unbind -n C-M-s
tmux unbind -n C-M-b
tmux unbind -n C-M-f
tmux unbind -n C-M-r
tmux unbind -n C-M-e
tmux unbind -n C-M-d
tmux unbind -n C-M-u
tmux unbind -n "${FLOAX_PREFIX}-s"
tmux unbind -n "${FLOAX_PREFIX}-b"
tmux unbind -n "${FLOAX_PREFIX}-f"
tmux unbind -n "${FLOAX_PREFIX}-r"
tmux unbind -n "${FLOAX_PREFIX}-e"
tmux unbind -n "${FLOAX_PREFIX}-d"
tmux unbind -n "${FLOAX_PREFIX}-u"
}

tmux_version() {
Expand Down Expand Up @@ -105,9 +108,11 @@ pop() {
-S fg="$FLOAX_BORDER_COLOR" \
-s fg="$FLOAX_TEXT_COLOR" \
-T "$FLOAX_TITLE" \
-x "$FLOAX_X" \
-y "$FLOAX_Y" \
-w "$FLOAX_WIDTH" \
-h "$FLOAX_HEIGHT" \
-b rounded \
-E \
"tmux attach-session -t \"$FLOAX_SESSION_NAME\""
"tmux attach-session -t \"$FLOAX_SESSION_NAME\""
}
4 changes: 2 additions & 2 deletions scripts/zoom-options.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ unlock_bindings() {

lock_bindings() {
unset_bindings
tmux bind -n C-M-u run "$CURRENT_DIR/zoom-options.sh unlock"
change_popup_title "Bindings locked. Unlock with [Ctrl-Alt-u]"
tmux bind -n "${FLOAX_PREFIX}-u" run "$CURRENT_DIR/zoom-options.sh unlock"
change_popup_title "Bindings locked. Unlock with [${FLOAX_PREFIX}-u]"
}

change_popup_title() {
Expand Down

0 comments on commit 7023ff0

Please sign in to comment.