Skip to content

Commit

Permalink
feat: pull config from /etc
Browse files Browse the repository at this point in the history
  • Loading branch information
simonwjackson committed Apr 13, 2024
1 parent 5d592ca commit 4a33e63
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 26 deletions.
14 changes: 14 additions & 0 deletions nix/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,24 @@ in {
default = package;
description = "The package to use for ${pname}.";
};

tmeshServerTmuxConfig = lib.mkOption {
type = lib.types.lines;
default = "";
description = "Tmux configuration for tmesh server.";
};

tmeshTmuxConfig = lib.mkOption {
type = lib.types.lines;
default = "";
description = "Tmux configuration for tmesh.";
};
};

config = lib.mkIf cfg.enable {
environment.etc."${pname}/config.json".source = jsonConfigFile;
environment.etc."${pname}/tmesh.tmux.conf".source = cfg.tmeshTmuxConfig;
environment.etc."${pname}/tmesh-server.tmux.conf".source = cfg.tmeshServerTmuxConfig;

environment.systemPackages = [
(pkgs.writeScriptBin "${pname}" ''
Expand Down
19 changes: 2 additions & 17 deletions src/bin/tmesh
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,19 @@ TMUX="${TMUX:-}"
TERM="${TERM:-}"
SERVER="${SERVER:=$(hostname)}"
SCRIPT_DIR="$(dirname "$0")"

TMESH_USER_CONFIG=${TMESH_USER_CONFIG:-}
TMUX_CONFIG=${TMUX_CONFIG:="/etc/tmesh/tmesh.tmux.conf"}
export TMESH_SOCKET=${TMESH_SOCKET:-"tmesh"}

read -r -d '' tmesh_default_config <<EOM
# INFO: https://github.com/tmux/tmux/wiki/Clipboard#terminal-support---tmux-inside-tmux
set -s set-clipboard on
set -as terminal-features ',@TERM:clipboard'
# Don't block inner tmux session, reassign the prefix
set -g prefix C-a
unbind-key C-b
bind-key C-a send-prefix
# Server Switcher
bind-key -n 'M-A' display-popup -E -w 80% -h 80% "${SCRIPT_DIR@Q}/choose-nest.sh"
# Local Mahine term
bind-key -n 'M-i' display-popup -E -w 80% -h 80%
set -g status off
EOM

tmesh_default_config=${tmesh_default_config/@TERM/$TERM}

tmux_config=(
"${tmesh_default_config[@]}"
"${TMESH_USER_CONFIG[@]}"
"${TMUX_CONFIG[@]}"
)

tryStartTmesh() {
Expand Down
14 changes: 5 additions & 9 deletions src/bin/tmesh-server
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,19 @@

SCRIPT_DIR="$(dirname "$0")"
TMESH_SERVER_SOCKET=${TMESH_SERVER_SOCKET:-"tmesh-server"}
TMUX_CONFIG=${TMUX_CONFIG:="${SCRIPT_DIR}/../etc/tmesh/tmesh-server.tmux.conf"}
TMUX_CONFIG=${TMUX_CONFIG:="/etc/tmesh/tmesh-server.tmux.conf"}
TMESH_CONFIG=${TMESH_CONFIG:="/etc/tmesh/config.json"}

COMMAND="$(yq -e -oy '.local-tmesh-server.command' "${TMESH_CONFIG}" 2>/dev/null || echo "${SHELL}")"
command="$(yq -e -oy '.local-tmesh-server.command' "${TMESH_CONFIG}" 2>/dev/null || echo "${SHELL}")"

read -r -d '' tmesh_default_config <<EOM
read -r -d '' tmesh_server_default_config <<EOM
# Project switcher
bind-key -n 'M-a' display-popup -E -w 80% -h 80% "${SCRIPT_DIR@Q}/choose-session.sh"
set -g status off
EOM

tmesh_server_default_config=${tmesh_default_config/@TERM/$TERM}

tmux_config=(
"${tmesh_server_default_config[@]}"
"${TMESH_USER_CONFIG[@]}"
"${TMESH_CONFIG[@]}"
)

tmux \
Expand All @@ -30,4 +26,4 @@ tmux \
-f <(printf "%s\n" "${tmux_config[@]}") \
new-session \
-s terminals \
"${COMMAND}" >/dev/null 2>&1
"${command}" >/dev/null 2>&1

0 comments on commit 4a33e63

Please sign in to comment.