From 2cacfb790752a1cc8520ced3147b5a7f7524c181 Mon Sep 17 00:00:00 2001 From: Florian Schmitt Date: Fri, 6 Dec 2024 10:29:41 +0300 Subject: [PATCH] feat(home): add scripts folder --- modules/home-config.nix | 44 ++++++++++----------- {dotfiles => scripts}/init_yeswiki_repos.sh | 0 scripts/tmux-sessionizer | 27 +++++++++++++ 3 files changed, 49 insertions(+), 22 deletions(-) rename {dotfiles => scripts}/init_yeswiki_repos.sh (100%) create mode 100755 scripts/tmux-sessionizer diff --git a/modules/home-config.nix b/modules/home-config.nix index 3353e53..16787ae 100644 --- a/modules/home-config.nix +++ b/modules/home-config.nix @@ -1,8 +1,9 @@ # Inject the right home-manager config for the machine. -{ config -, pkgs -, lib -, ... +{ + config, + pkgs, + lib, + ... }: let # plasma-manager = pkgs.fetchFromGitHub { @@ -239,7 +240,7 @@ in #tmux = "tmux -f ~/.config/tmux/tmux.conf attach || tmux -f ~/.config/tmux/tmux.conf new"; bunx = "bun --bun x"; g = "lazygit"; - t = "/usr/bin/tmux-sessionizer"; + t = "/home/mrflos/Code/nixos-config/scripts/tmux-sessionizer"; kdenix = "nix run github:pjones/plasma-manager --extra-experimental-features nix-command --extra-experimental-features flakes > /home/mrflos/Developpements/nixos-config/modules/home-plasma.nix"; icat = "kitty +kitten icat"; nixedit = "vi /etc/nixos"; @@ -248,7 +249,7 @@ in socks = "ssh -N -f -C -D 9090 mrflos@yunohost.yeswiki.net -p 6742"; vi = "/run/current-system/sw/bin/nvim"; vim = "/run/current-system/sw/bin/nvim"; - yeswiki-updater = "cd /home/mrflos/Developpements/yeswiki-installer/ && sudo php yeswiki-updater.php"; + yeswiki-updater = "cd /home/mrflos/Code/yeswiki-installer/ && sudo php yeswiki-updater.php"; }; initExtra = '' export BUN_INSTALL="$HOME/.bun" @@ -344,22 +345,21 @@ in # workspaces # binds $mod + [shift +] {1..10} to [move to] workspace {1..10} builtins.concatLists ( - builtins.genList - ( - x: - let - ws = - let - c = (x + 1) / 10; - in - builtins.toString (x + 1 - (c * 10)); - in - [ - "$mod, ${ws}, workspace, ${toString (x + 1)}" - "$mod SHIFT, ${ws}, movetoworkspace, ${toString (x + 1)}" - "$mod ALT, ${ws}, movetoworkspacesilent, ${toString (x + 1)}" # Move window silently to workspace Super + Alt + [0-9] - ] - ) 10 + builtins.genList ( + x: + let + ws = + let + c = (x + 1) / 10; + in + builtins.toString (x + 1 - (c * 10)); + in + [ + "$mod, ${ws}, workspace, ${toString (x + 1)}" + "$mod SHIFT, ${ws}, movetoworkspace, ${toString (x + 1)}" + "$mod ALT, ${ws}, movetoworkspacesilent, ${toString (x + 1)}" # Move window silently to workspace Super + Alt + [0-9] + ] + ) 10 ) ); diff --git a/dotfiles/init_yeswiki_repos.sh b/scripts/init_yeswiki_repos.sh similarity index 100% rename from dotfiles/init_yeswiki_repos.sh rename to scripts/init_yeswiki_repos.sh diff --git a/scripts/tmux-sessionizer b/scripts/tmux-sessionizer new file mode 100755 index 0000000..ca3f019 --- /dev/null +++ b/scripts/tmux-sessionizer @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +pushd ~/Code +if [[ $# -eq 1 ]]; then + selected=$1 +else + selected=$(find . -mindepth 1 -maxdepth 1 -type d | fzf) +fi + +if [[ -z $selected ]]; then + exit 0 +fi + +selected_name=$(basename "$selected" | tr . _) +tmux_running=$(pgrep tmux) + +if [[ -z $TMUX ]] && [[ -z $tmux_running ]]; then + tmux new-session -s $selected_name -c $selected + exit 0 +fi + +if ! tmux has-session -t=$selected_name 2> /dev/null; then + tmux new-session -ds $selected_name -c $selected +fi + +tmux switch-client -t $selected_name +popd