[feat] Update flake.lock and add start-tmux script

This commit is contained in:
Uttarayan
2024-02-15 01:56:27 +05:30
parent 5261d5be5f
commit 58084329f5
3 changed files with 232 additions and 183 deletions

30
config/nix/flake.lock generated
View File

@@ -44,11 +44,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1704982712, "lastModified": 1706830856,
"narHash": "sha256-2Ptt+9h8dczgle2Oo6z5ni5rt/uLMG47UFTR1ry/wgg=", "narHash": "sha256-a0NYyp+h9hlb7ddVz4LUn1vT/PLwqfrWYcHMvFB1xYg=",
"owner": "hercules-ci", "owner": "hercules-ci",
"repo": "flake-parts", "repo": "flake-parts",
"rev": "07f6395285469419cf9d078f59b5b49993198c00", "rev": "b253292d9c0a5ead9bc98c4e9a26c6312e27d69f",
"type": "github" "type": "github"
}, },
"original": { "original": {
@@ -125,11 +125,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1707683400, "lastModified": 1707919853,
"narHash": "sha256-Zc+J3UO1Xpx+NL8UB6woPHyttEy9cXXtm+0uWwzuYDc=", "narHash": "sha256-qxmBGDzutuJ/tsX4gp+Mr7fjxOZBbeT9ixhS5o4iFOw=",
"owner": "nix-community", "owner": "nix-community",
"repo": "home-manager", "repo": "home-manager",
"rev": "21b078306a2ab68748abf72650db313d646cf2ca", "rev": "043ba285c6dc20f36441d48525402bcb9743c498",
"type": "github" "type": "github"
}, },
"original": { "original": {
@@ -148,11 +148,11 @@
}, },
"locked": { "locked": {
"dir": "contrib", "dir": "contrib",
"lastModified": 1706140641, "lastModified": 1707868264,
"narHash": "sha256-H1qHhkf7sF7yrG2rb9Ks1Y4EtLY3cXGp16KCGveJWY4=", "narHash": "sha256-Ewc5fxKb09XQeO6LeKmko0x7MxKmVCGUYwKq7w8sZD0=",
"owner": "neovim", "owner": "neovim",
"repo": "neovim", "repo": "neovim",
"rev": "4e59422e1d4950a3042bad41a7b81c8db4f8b648", "rev": "a376d979bda103fa9998d05c3cc4ba56d3c3cece",
"type": "github" "type": "github"
}, },
"original": { "original": {
@@ -171,11 +171,11 @@
"nixpkgs": "nixpkgs" "nixpkgs": "nixpkgs"
}, },
"locked": { "locked": {
"lastModified": 1706141075, "lastModified": 1707935913,
"narHash": "sha256-o66/XFTXmcJSpEcO508V5r765HtgT8qtr+H4LRIB9BY=", "narHash": "sha256-uAkWeyJUNyZS9/u9huCoAJXyTiHw1F+5a91IDujPppk=",
"owner": "nix-community", "owner": "nix-community",
"repo": "neovim-nightly-overlay", "repo": "neovim-nightly-overlay",
"rev": "1da2e054a16309d7d7f7669438c8b9a5ef1b4642", "rev": "b57bf64254630de4920177333f06b341653b1f28",
"type": "github" "type": "github"
}, },
"original": { "original": {
@@ -186,11 +186,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1706006310, "lastModified": 1707877513,
"narHash": "sha256-nDPz0fj0IFcDhSTlXBU2aixcnGs2Jm4Zcuoj0QtmiXQ=", "narHash": "sha256-sp0w2apswd3wv0sAEF7StOGHkns3XUQaO5erhWFZWXk=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "b43bb235efeab5324c5e486882ef46749188eee2", "rev": "89653a03e0915e4a872788d10680e7eec92f8600",
"type": "github" "type": "github"
}, },
"original": { "original": {

View File

@@ -2,7 +2,9 @@
config, config,
pkgs, pkgs,
... ...
}: }: let
start-tmux = (import ./scripts/start-tmux.nix) pkgs;
in
# https://mipmip.github.io/home-manager-option-search/ # https://mipmip.github.io/home-manager-option-search/
{ {
imports = [ imports = [
@@ -22,6 +24,7 @@
g = "git"; g = "git";
cd = "z"; cd = "z";
ls = "exa"; ls = "exa";
t = "${start-tmux}";
}; };
interactiveShellInit = '' interactiveShellInit = ''
set fish_greeting set fish_greeting
@@ -154,10 +157,8 @@
]; ];
file = { file = {
# # Building this configuration will create a copy of 'dotfiles/screenrc' in ".config/tmux/sessions".source = ../tmux/sessions;
# # the Nix store. Activating the configuration will then make '~/.screenrc' a ".config/nvim".source = ../nvim;
# # symlink to the Nix store copy.
# ".screenrc".source = dotfiles/screenrc;
# # You can also set the file content immediately. # # You can also set the file content immediately.
# ".gradle/gradle.properties".text = '' # ".gradle/gradle.properties".text = ''

View File

@@ -0,0 +1,48 @@
{
pkgs,
...
}:
pkgs.writeShellScript "start-tmux" ''
live_sessions=$(${pkgs.tmux}/bin/tmux list-sessions 2>/dev/null)
all_sessions=$(${pkgs.findutils}/bin/find -L ~/.config/tmux/sessions -type f -executable -printf '%f\n'| sort)
TMUX_SESSIONS="$HOME/.config/tmux/sessions"
# for some reason ~/.config/tmux/session doesn't work if made with quotes
# TMUX_SESSIONS=$XDG_CONFIG_HOME/tmux/sessions
if ! [ -z "$TMUX" ];then
echo "Nested tmux sessions are a bad idea?"
echo "If you want to really do this unset TMUX environment variable"
exit 1
fi
IFS=$'\n'
for live_session in $live_sessions;do
live_session_name=$(echo $live_session | ${pkgs.coreutils}/bin/cut -d: -f1)
if [ -z "''\${all_sessions##*$live_session_name*}" ];then # see https://stackoverflow.com/questions/229551/how-to-check-if-a-string-contains-a-substring-in-bash
all_sessions="$(echo "$all_sessions" | sed "s/$live_session_name/$live_session/g")"
else
all_sessions=$(echo -e "$all_sessions\n$live_session")
# Okay I know this is ugly it is 5:13 my brain is not working
fi
session=$(echo "''\$all_sessions" | fzf)
session_name=$(echo $session | cut -d: -f1)
if [ -z "$session" ];then
exit 0
fi
if ! [ -z "''\${session##*created*}" ];then
if [ -x "$TMUX_SESSIONS/$session_name" ];then
source $TMUX_SESSIONS/$session_name
else
echo $TMUX_SESSIONS/$session_name not found or is not executable
exit 1
fi
fi
if [ -z "''\${session##*attached*}" ];then
read -r -p "The session is already attached somewhere else. Attach it here too ? (y/N): " choice
if [ "$choice" == "y" ] || [ "$choice" == "Y" ];then
tmux attach-session -t$session_name
fi
else
tmux attach-session -t$session_name
fi
done
''