diff --git a/lib/shared/scripts/t.nix b/lib/shared/scripts/t.nix index 7a65aae5..f5aff039 100644 --- a/lib/shared/scripts/t.nix +++ b/lib/shared/scripts/t.nix @@ -33,7 +33,7 @@ exit fi - # TODO: support .ignored/.tmux + # TODO: refactor to a function that works for both .tmux and .ignored/.tmux files. if [[ -x "''${SELECTED_PATH}/.tmux" ]]; then DIGEST="$(openssl sha512 "''${SELECTED_PATH}/.tmux")" @@ -55,6 +55,27 @@ tmux new-session -d -c "''${SELECTED_PATH}" -s "''${SESSION_NAME}" (cd "''${SELECTED_PATH}" && "''${SELECTED_PATH}/.tmux" "''${SESSION_NAME}") fi + elif [[ -x "''${SELECTED_PATH}/.ignored/.tmux" ]]; then + DIGEST="$(openssl sha512 "''${SELECTED_PATH}/.ignored/.tmux")" + + # Prompt the first time we see a given .ignored/.tmux file before running it. + if ! grep -q "''${DIGEST}" ~/..ignored/.tmux.digests 2> /dev/null; then + cat "''${SELECTED_PATH}/.ignored/.tmux" + + read -r -n 1 -p "Trust (and run) this .tmux file? (t = trust, otherwise = skip) " + + if [[ $REPLY =~ ^[Tt]$ ]]; then + echo "''${DIGEST}" >> ~/..tmux.digests + + # Create a new session and run the .ignored/.tmux script. + tmux new-session -d -c "''${SELECTED_PATH}" -s "''${SESSION_NAME}" + (cd "''${SELECTED_PATH}" && "''${SELECTED_PATH}/.ignored/.tmux" "''${SESSION_NAME}") + fi + else + # Create a new session and run the .tmux script. + tmux new-session -d -c "''${SELECTED_PATH}" -s "''${SESSION_NAME}" + (cd "''${SELECTED_PATH}" && "''${SELECTED_PATH}/.tmux" "''${SESSION_NAME}") + fi fi # If there is no session, create one.