diff --git a/nix/pkgs/default.nix b/nix/pkgs/default.nix index a5fe44c..84a76b7 100644 --- a/nix/pkgs/default.nix +++ b/nix/pkgs/default.nix @@ -9,7 +9,7 @@ in build-glove80 = callPackage ./build-glove80.nix { }; notes = callPackage ./notes.nix { }; i3-battery-popup = callPackage ./i3-battery-popup.nix { }; - tmux-sessionizer = callPackage ./tmux-sessionizer.nix { }; + tmux-sessionizer = callPackage ./tmux-sessionizer { }; upload-to-files = callPackage ./upload-to-files.nix { }; vimPlugins = prev.vimPlugins // vimPlugins; diff --git a/nix/pkgs/tmux-sessionizer.nix b/nix/pkgs/tmux-sessionizer.nix deleted file mode 100644 index 1590b6a..0000000 --- a/nix/pkgs/tmux-sessionizer.nix +++ /dev/null @@ -1,59 +0,0 @@ -{ pkgs }: - -pkgs.writeShellApplication { - name = "tmux-sessionizer"; - - runtimeInputs = with pkgs; [ tmux ]; - - text = '' - set +o nounset - - # Based on https://github.com/ThePrimeagen/tmux-sessionizer. - - switch_to() { - if [[ -z $TMUX ]]; then - tmux attach-session -t "$1" - else - tmux switch-client -t "$1" - fi - } - - has_session() { - tmux list-sessions | grep -q "^$1:" - } - - hydrate() { - if [ -f "$2/.tmux-sessionizer" ]; then - tmux send-keys -t "$1" "source $2/.tmux-sessionizer" Enter - elif [ -f "$HOME/.tmux-sessionizer" ]; then - tmux send-keys -t "$1" "source $HOME/.tmux-sessionizer" Enter - fi - } - - if [[ $# -eq 1 ]]; then - selected=$1 - else - selected=$(find -L ~/ ~/Code ~/Code/personal ~/Code/os ~/Documents -mindepth 1 -maxdepth 1 -type d ! -name "*.old" | 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" - hydrate "$selected_name" "$selected" - exit 0 - fi - - if ! has_session "$selected_name"; then - tmux new-session -ds "$selected_name" -c "$selected" - hydrate "$selected_name" "$selected" - fi - - switch_to "$selected_name" - ''; -} diff --git a/nix/pkgs/tmux-sessionizer/configure-directories.patch b/nix/pkgs/tmux-sessionizer/configure-directories.patch new file mode 100644 index 0000000..49fddfd --- /dev/null +++ b/nix/pkgs/tmux-sessionizer/configure-directories.patch @@ -0,0 +1,15 @@ +diff --git a/tmux-sessionizer b/tmux-sessionizer +index fa1bec5..4d79e0b 100755 +--- a/tmux-sessionizer ++++ b/tmux-sessionizer +@@ -22,9 +22,7 @@ hydrate() { + if [[ $# -eq 1 ]]; then + selected=$1 + else +- # If someone wants to make this extensible, i'll accept +- # PR +- selected=$(find ~/ ~/personal ~/personal/dev/env/.config -mindepth 1 -maxdepth 1 -type d | fzf) ++ selected=$(find -L ~/ ~/Code ~/Documents -mindepth 1 -maxdepth 1 -type d | sort | fzf) + fi + + if [[ -z $selected ]]; then diff --git a/nix/pkgs/tmux-sessionizer/default.nix b/nix/pkgs/tmux-sessionizer/default.nix new file mode 100644 index 0000000..8e15b3f --- /dev/null +++ b/nix/pkgs/tmux-sessionizer/default.nix @@ -0,0 +1,27 @@ +{ pkgs, ... }: + +pkgs.stdenv.mkDerivation rec { + pname = "tmux-sessonizer"; + version = "0.1.0"; + + src = pkgs.fetchFromGitHub { + owner = "theprimeagen"; + repo = "tmux-sessionizer"; + rev = "master"; + sha256 = "bZXt9TyMU1Ed/WR0/ahMQ4oyIi6yXLKnXKYPPNBt/s4="; + }; + + buildInputs = with pkgs; [ + bash + fzf + tmux + ]; + + patches = [ ./configure-directories.patch ]; + + installPhase = '' + mkdir -p $out/bin + cp tmux-sessionizer $out/bin/tmux-sessionizer + chmod +x $out/bin/tmux-sessionizer + ''; +}