diff --git a/README.md b/README.md index 14408270..d75579fe 100644 --- a/README.md +++ b/README.md @@ -34,3 +34,7 @@ First run: Afterwards, run: `make rebuild`. ## TODO + +## Edit the prompt with $EDITOR. + +- `alt+e` to edit the prompt. diff --git a/conf/ghostty/config b/conf/ghostty/config index a280b46d..e61dd91f 100644 --- a/conf/ghostty/config +++ b/conf/ghostty/config @@ -6,22 +6,24 @@ theme = dark:Kanagawa Dragon,light:Builtin Solarized Light font-family = Berkeley Mono Nerd Font # font-family = Iosevka Nerd Font Mono -font-size = 14 -font-thicken = true +font-size = 13 +font-thicken = false font-codepoint-map = U+4E00-U+9FFF,U+3400-U+4DBF=LXGW WenKai Mono shell-integration-features = cursor,sudo,title cursor-style = block cursor-invert-fg-bg = true +selection-invert-fg-bg = true macos-option-as-alt = true macos-titlebar-style = tabs macos-window-shadow = true adjust-underline-position = 45% -adjust-underline-thickness = -65% +adjust-underline-thickness = mouse-hide-while-typing = true focus-follows-mouse = false unfocused-split-opacity = 1 window-padding-balance = true -window-padding-x = 6 +window-padding-x = 8 +window-padding-y = 0 background-opacity = 1 background-blur-radius = 0 @@ -33,74 +35,17 @@ quick-terminal-position = top # keybinds -## https://www.eso.org/~ndelmott/ascii.html -## ctrl+z is the prefix for tmux -## \x1a is ctrl+z keybind = clear keybind = super+shift+r=reload_config keybind = super+backslash=toggle_quick_terminal -# keybind = super+n=text:\x1ac -# keybind = super+left_bracket=text:\x1ap -# keybind = super+right_bracket=text:\x1an -# keybind = super+slash=text:\x1a/ -# keybind = super+minus=text:\x1a- -# keybind = super+w=text:\x1aw -# keybind = super+one=text:\x1a1 -# keybind = super+two=text:\x1a2 -# keybind = super+three=text:\x1a3 -# keybind = super+four=text:\x1a4 - -# ==== keybind = super+v=paste_from_clipboard keybind = super+c=copy_to_clipboard -keybind = super+n=new_window -keybind = super+t=new_tab -keybind = super+w=close_surface -keybind = super+shift+w=close_window -keybind = super+slash=new_split:right -keybind = super+minus=new_split:down -keybind = super+left_bracket=previous_tab -keybind = super+right_bracket=next_tab -keybind = super+comma=last_tab -keybind = alt+left_bracket=move_tab:-1 -keybind = alt+right_bracket=move_tab:1 -## goto_tab:1 and 2,3,4,5,6,7,8,9 -keybind = super+one=goto_tab:1 -keybind = super+two=goto_tab:2 -keybind = super+three=goto_tab:3 -keybind = super+four=goto_tab:4 -keybind = super+five=goto_tab:5 -keybind = super+six=goto_tab:6 -keybind = super+seven=goto_tab:7 -keybind = super+eight=goto_tab:8 -keybind = super+nine=goto_tab:9 - -# # navigate with alt+hjkl -keybind = alt+h=goto_split:left -keybind = alt+l=goto_split:right -keybind = alt+k=goto_split:top -keybind = alt+j=goto_split:bottom -# # resize with super+shift+hjkl -keybind = alt+shift+h=resize_split:left,60 -keybind = alt+shift+l=resize_split:right,60 -keybind = alt+shift+k=resize_split:up,60 -keybind = alt+shift+j=resize_split:down,60 -keybind = alt+shift+equal=equalize_splits -# # toggle zoom on split -keybind = super+0=toggle_split_zoom -# # toggle fullscreen -keybind = ctrl+a>f=toggle_fullscreen -# select all -keybind = super+a=select_all -# clear screen -keybind = ctrl+l=clear_screen -# scroll to top -keybind = ctrl+a>y=scroll_to_top -# # scroll to bottom -keybind = ctrl+a>e=scroll_to_bottom -# scroll_page_up and scroll_page_down -keybind = super+d=scroll_page_down -keybind = super+u=scroll_page_up -# jump_to_prompt=-1, jump_to_prompt=1 keybind = alt+d=jump_to_prompt:-1 keybind = alt+u=jump_to_prompt:1 +# # toggle fullscreen +keybind = super+f12=toggle_fullscreen + +### custom + +config-file = ?config-tmux +# config-file = ?config-default-keybind diff --git a/conf/ghostty/config-default-keybind b/conf/ghostty/config-default-keybind new file mode 100644 index 00000000..a591c37a --- /dev/null +++ b/conf/ghostty/config-default-keybind @@ -0,0 +1,48 @@ +keybind = super+n=new_window +keybind = super+t=new_tab +keybind = super+w=close_surface +keybind = super+shift+w=close_window +keybind = super+slash=new_split:right +keybind = super+minus=new_split:down +keybind = super+left_bracket=previous_tab +keybind = super+right_bracket=next_tab +keybind = super+comma=last_tab +keybind = alt+left_bracket=move_tab:-1 +keybind = alt+right_bracket=move_tab:1 +## goto_tab:1 and 2,3,4,5,6,7,8,9 +keybind = super+one=goto_tab:1 +keybind = super+two=goto_tab:2 +keybind = super+three=goto_tab:3 +keybind = super+four=goto_tab:4 +keybind = super+five=goto_tab:5 +keybind = super+six=goto_tab:6 +keybind = super+seven=goto_tab:7 +keybind = super+eight=goto_tab:8 +keybind = super+nine=goto_tab:9 + +# # navigate with alt+hjkl +keybind = alt+h=goto_split:left +keybind = alt+l=goto_split:right +keybind = alt+k=goto_split:top +keybind = alt+j=goto_split:bottom +# # resize with super+shift+hjkl +keybind = alt+shift+h=resize_split:left,60 +keybind = alt+shift+l=resize_split:right,60 +keybind = alt+shift+k=resize_split:up,60 +keybind = alt+shift+j=resize_split:down,60 +keybind = alt+shift+equal=equalize_splits +# # toggle zoom on split +keybind = super+0=toggle_split_zoom +# select all +keybind = super+a=select_all +# clear screen +keybind = ctrl+l=clear_screen +# scroll to top +keybind = ctrl+a>y=scroll_to_top +# # scroll to bottom +keybind = ctrl+a>e=scroll_to_bottom +# scroll_page_up and scroll_page_down +keybind = super+d=scroll_page_down +keybind = super+u=scroll_page_up +# jump_to_prompt=-1, jump_to_prompt=1 + diff --git a/conf/ghostty/config-tmux b/conf/ghostty/config-tmux new file mode 100644 index 00000000..817a04f8 --- /dev/null +++ b/conf/ghostty/config-tmux @@ -0,0 +1,23 @@ +macos-titlebar-style = hidden + +#### keybinds + +# https://www.eso.org/~ndelmott/ascii.html +# ctrl+z is the prefix for tmux +# \x1a is ctrl+z +# +keybind = super+n=text:\x1ac +keybind = super+left_bracket=text:\x1ap +keybind = super+right_bracket=text:\x1an +keybind = super+slash=text:\x1a/ +keybind = super+minus=text:\x1a- +keybind = super+w=text:\x1aw +keybind = super+one=text:\x1a1 +keybind = super+two=text:\x1a2 +keybind = super+three=text:\x1a3 +keybind = super+four=text:\x1a4 + +keybind = super+h=text:\x1bh +keybind = super+l=text:\x1bl +keybind = super+j=text:\x1bj +keybind = super+k=text:\x1bk diff --git a/conf/tig/vim.tigrc b/conf/tig/vim.tigrc index f61624b4..fa9ccc55 100644 --- a/conf/tig/vim.tigrc +++ b/conf/tig/vim.tigrc @@ -6,6 +6,7 @@ bind generic j move-down bind generic k move-up bind generic l scroll-right bind generic ge edit +bind diff ge >nvim -c "Gpedit %(commit):%(file)" bind generic gE >nvim -c "Gedit %(commit)" bind generic refresh @@ -22,9 +23,11 @@ bind generic g- parent bind generic gb back bind generic gn view-next # git push to remote -bind main gup ?+git push --force-with-lease origin %(branch) -bind main gff ?+git fetch origin %(branch) -bind main gpp ?git pull origin %(branch) +bind generic guP ?+git push --force-with-lease origin %(branch) +bind generic gup !git push origin %(branch) +bind generic gff !git fetch origin %(branch) +bind generic gpp !git pull --ff --prune --no-tags origin %(branch) +bind main gfp !git fetch --prune --prune-tags bind main gfa ?+git fetch --all bind main gca +git commit --amend --no-edit bind main rh ?git reset --hard %(commit) diff --git a/conf/tmux/bin/tmux-scratch-toggle.tmux b/conf/tmux/bin/tmux-scratch-toggle.tmux index 37108a84..9eea1a11 100755 --- a/conf/tmux/bin/tmux-scratch-toggle.tmux +++ b/conf/tmux/bin/tmux-scratch-toggle.tmux @@ -2,7 +2,9 @@ scratch_session_name="FLOAT" -if [[ $current_session == "FLOAT" ]]; then +current_session=$(tmux display-message -p '#{session_name}') + +if [[ $current_session == "$scratch_session_name" ]]; then if [[ "$TMUX_IS_POPUP" == "1" ]]; then tmux detach exit 0 diff --git a/flake.nix b/flake.nix index 2232596b..0d49c825 100644 --- a/flake.nix +++ b/flake.nix @@ -101,7 +101,7 @@ inherit mkSystemConfig inputs nixpkgs nixpkgs-stable home-manager mac-app-util darwin; } ); - formatter = forAllSystems (system: nixpkgs.legacyPackages.${system}.alejandra); + formatter = forAllSystems (system: nixpkgs.legacyPackages.${system}.nixfmt-rfc-style); }; # ========================================================================= diff --git a/nix/darwin/intel.nix b/nix/darwin/intel.nix index e3f60836..03ce9408 100644 --- a/nix/darwin/intel.nix +++ b/nix/darwin/intel.nix @@ -19,7 +19,7 @@ NSAutomaticSpellingCorrectionEnabled = false; }; dock = { - autohide = true; + autohide = false; largesize = 42; tilesize = 40; magnification = true; diff --git a/nix/darwin/jankyborders.nix b/nix/darwin/jankyborders.nix index 8969fb70..ce73e33b 100644 --- a/nix/darwin/jankyborders.nix +++ b/nix/darwin/jankyborders.nix @@ -7,7 +7,7 @@ let "style=round" "active_color=0xffbd93f9" "inactive_color=0xffabb2bf" - "width=4.0" + "width=6.0" "hidpi=on" "ax_focus=on" "blacklist='LaunchBar'" diff --git a/nix/hm/fish.nix b/nix/hm/fish.nix index ca79a923..4b403b1d 100644 --- a/nix/hm/fish.nix +++ b/nix/hm/fish.nix @@ -89,6 +89,7 @@ gtail = "git rev-list --all | tail"; ggrep = "git rev-list --all | xargs git grep --break"; tig = "TERM=xterm-256color ${pkgs.tig}/bin/tig"; + lg = "lazygit"; flog = "glog"; xmerge = "git merge --ff"; xmerged = "git branch --merged master"; @@ -110,9 +111,12 @@ ''; emptytrash = "sudo rm -rf ~/.Trash/*"; kittyconf = "nvim ~/.config/kitty/kitty.conf"; + stop-yabai = "yabai --stop-service"; + start-yabai = "yabai --start-service"; # yabaiconf="nvim ~/.config/yabai/yabairc"; skhdconf = "nvim ~/.config/skhd/skhdrc"; - tmuxin = "tmux new-session -A -s Main"; + tmuxin = "tmux new-session -A -s tmux"; + quickterm = "tmux new-session -A -s quickterm -c $HOME/workspace"; tm-rw = "tmux rename-window"; tm-rs = "tmux rename-session"; tail-tmp-log = "tail -f (fd --type file --search-path /tmp | fzf)"; diff --git a/nix/hm/frontend-dev.nix b/nix/hm/frontend-dev.nix index e29949ea..f63b9c36 100644 --- a/nix/hm/frontend-dev.nix +++ b/nix/hm/frontend-dev.nix @@ -35,7 +35,7 @@ ]; programs.fish.interactiveShellInit = '' - eval "$(fnm env --use-on-cd)" + eval "$(fnm env)" # otherwise in interactive shell, npm bins not available fish_add_path "$NPM_CONFIG_PREFIX/bin" ''; diff --git a/nix/hm/git.nix b/nix/hm/git.nix index 90080bbc..8e92ebb9 100644 --- a/nix/hm/git.nix +++ b/nix/hm/git.nix @@ -3,9 +3,11 @@ lib, theme, ... -}: let +}: +let enable_delta = true; -in { +in +{ home.packages = with pkgs; [ # github cli, manage repo, gists etc. gh @@ -19,6 +21,12 @@ in { guiSupport = false; }; + difftastic = { + # enable this need to disable delta. + enable = false; + background = "dark"; + }; + aliases = { co = "checkout"; ad = "add"; @@ -139,11 +147,7 @@ in { core = { ignorecase = false; autocrlf = "input"; - pager = lib.mkForce ( - if enable_delta - then "${pkgs.delta}/bin/delta" - else "less" - ); + pager = lib.mkForce (if enable_delta then "${pkgs.delta}/bin/delta" else "less"); }; rerere = { enabled = true; @@ -174,11 +178,18 @@ in { algorithm = "histogram"; compactionHeuristic = true; guitool = "vscode"; + tool = "nvim"; }; difftool = { vscode = { cmd = ''code --wait --diff $LOCAL $REMOTE''; }; + nvim = { + cmd = ''nvim -d "$REMOTE" "$LOCAL"''; + }; + difft = { + cmd = ''difft --color=always "$REMOTE" "$LOCAL"''; + }; }; mergetool = { keepBackup = false; @@ -198,7 +209,7 @@ in { remote = "green"; }; }; - interactive = lib.mkIf enable_delta {diffFilter = "${pkgs.delta}/bin/delta --color-only";}; + interactive = lib.mkIf enable_delta { diffFilter = "${pkgs.delta}/bin/delta --color-only"; }; advice = { detachedHead = true; }; diff --git a/nix/hm/kitty.nix b/nix/hm/kitty.nix index b9fdc829..cbfe5e3d 100644 --- a/nix/hm/kitty.nix +++ b/nix/hm/kitty.nix @@ -7,10 +7,10 @@ tmux = "${pkgs.tmux}/bin/tmux"; tmux_keymaps = { "super+n" = "launch_silent ${tmux} new-window -a -c #{pane_current_path}"; - "super+-" = "launch_silent ${tmux} split-window -l 25% -v -c #{pane_current_path}"; - "super+\\" = "launch_silent ${tmux} split-window -l 25% -h -c #{pane_current_path}"; + "super+-" = "launch_silent ${tmux} split-window -l 45% -v -c #{pane_current_path}"; + # "super+\\" = "launch_silent ${tmux} split-window -l 25% -h -c #{pane_current_path}"; # don't know why, but the slash not working in some keyboard or old kitty version? - "super+/" = "launch_silent ${tmux} split-window -l 25% -h -c #{pane_current_path}"; + "super+/" = "launch_silent ${tmux} split-window -l 45% -h -c #{pane_current_path}"; "super+z" = "launch_silent ${tmux} select-window -l"; # "super+w" = "launch_silent ${tmux} last-pane"; "super+w" = "launch_silent ${tmux} choose-tree -Zw -O index"; @@ -94,8 +94,8 @@ in { disable_ligatures = "always"; clear_all_shortcuts = "yes"; macos_option_as_alt = "both"; - # hide_window_decorations = "titlebar-only"; - hide_window_decorations = "no"; + hide_window_decorations = "titlebar-only"; + # hide_window_decorations = "no"; notify_on_cmd_finish = "unfocused"; }; keybindings = diff --git a/nix/hm/lazygit.nix b/nix/hm/lazygit.nix new file mode 100644 index 00000000..bb17f8f8 --- /dev/null +++ b/nix/hm/lazygit.nix @@ -0,0 +1,76 @@ +{ ... }: +{ + # docs: https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md + programs.lazygit = { + enable = true; + settings = { + gui = { + theme = { + # selectedLineBgColor = [ + # ]; + }; + mouseEvents = true; + showFileTree = true; + commitHashLength = 6; + showDivergenceFromBaseBranch = "arrowAndNumber"; + enlargedSideViewLocation = "top"; + showBottomLine = false; + commandLogSize = 4; + expandFocusedSidePanel = true; + nerdFontsVersion = "3"; + windowSize = "half"; # "full" | "half" | "default" + border = "single"; + animateExplosion = false; + portraitMode = "auto"; # "never" | "always" | "auto" + filterMode = "fuzzy"; # "fuzzy" | "substring(default)" + statusPanelView = "dashboard"; # "dashboard" | "allBranchesLog" + }; + git = { + merging = { + args = "--no-ff"; + }; + skipHookPrefix = "WIP"; + autoFetch = true; + autoRefresh = true; + fetchAll = false; + paging = { + colorArg = "always"; + pager = "delta --dark --paging=never"; + externalDiffCommand = "difft --color=always"; + }; + }; + update = { + method = "never"; + }; + os = { + edit = "nvim"; + editPreset = "nvim-remote"; + editAtLine = "nvim +{{line}} {{filename}}"; + }; + # https://github.com/jesseduffield/lazygit/blob/master/docs/Custom_Command_Keybindings.md + customCommands = [ + { + key = "H"; + context = "commits"; + command = "gh browse {{.SelectedCommit.Sha}}"; + } + # in diff view, open file in nvim at selected commit + { + key = "E"; + context = "commitFiles"; + command = "nvim -c 'Gedit {{.SelectedCommit.Sha}}:{{.SelectedFile.Name}}'"; + } + ]; + quitOnTopLevelReturn = false; + disableStartupPopups = true; + promptToReturnFromSubprocess = false; + notARepository = "quit"; + keybinding = { + universal = { + quit = ""; + quitWithoutChangingDirectory = "Q"; + }; + }; + }; + }; +} diff --git a/nix/hm/skhd.nix b/nix/hm/skhd.nix index aadc8597..f37c2205 100644 --- a/nix/hm/skhd.nix +++ b/nix/hm/skhd.nix @@ -2,324 +2,347 @@ pkgs, config, ... -}: { +}: +{ home.packages = [ pkgs.skhd pkgs.jq # pkgs.bash ]; # home.file."${config.home.homeDirectory}/Applications/skhd".source = "${pkgs.skhd}/bin/skhd"; - xdg.configFile = let - jqbin = "${pkgs.jq}/bin/jq"; - bashbin = "${pkgs.bash}/bin/bash"; - skhdDir = "${config.xdg.configHome}/skhd"; - skhd = "${pkgs.skhd}/bin/skhd"; - bash = "${pkgs.bash}/bin/bash"; - in { - "skhd/skhdrc".text = '' - # https://github.com/nikhgupta/dotfiles/blob/c545755f782cd1cee90c7a7307ff17f730c18e09/config/skhd/skhdrc - # @see key code: https://github.com/koekeishiya/skhd/issues/1 - # see: https://github.com/solomonbroadbent/dotfiles/blob/2f6c660c15e2050785ed1f08aaf89c199ffacc3d/.skhdrc#L1 - # see keyboard codes: https://cloud.githubusercontent.com/assets/6175959/18551554/35137fc6-7b59-11e6-81a0-bef19ed5db5e.png - # powerfull mode declaration - :: default - - :: mode_window @ - :: mode_window_move @ - :: mode_window_move_space @ - :: mode_window_move_display @ - :: mode_window_toggle @ - :: mode_window_stack @ - :: mode_window_resize @ - - :: mode_space @ - :: mode_space_arrange @ - - :: mode_display @ - - # define escape as exit from every mode - mode_window < escape ; default - mode_window_move < escape ; default - mode_window_move_space < escape ; default - mode_window_move_display < escape ; default - mode_window_toggle < escape ; default - mode_window_stack < escape ; default - mode_window_resize < escape ; default - mode_space < escape ; default - mode_space_arrange < escape ; default - mode_display < escape ; default - - # define mode entry - ctrl+shift+alt - space ; default - ctrl+shift+alt - w ; mode_window - mode_window < m ; mode_window_move - mode_window_move < s ; mode_window_move_space - mode_window_move < d ; mode_window_move_display - mode_window < t ; mode_window_toggle - mode_window < s ; mode_window_stack - mode_window < r ; mode_window_resize - - ctrl+shift+alt - s ; mode_space - mode_space < a ; mode_space_arrange - - ctrl+shift+alt - d ; mode_display - - ## ============== manage windows - mode_window < x : yabai -m window --close; skhd -k "escape" - mode_window < return : yabai -m window --toggle zoom-fullscreen; skhd -k "escape" - # current window will be in float state, out control of current space layout. - mode_window_toggle < f : yabai -m window --toggle float; skhd -k "escape" - # make current window stick to current space layout. - mode_window_toggle < a : yabai -m window --toggle sticky; skhd -k "escape" - - mode_window < h : yabai -m window --focus west; ${skhd} -k "escape" - mode_window < j : yabai -m window --focus south; ${skhd} -k "escape" - mode_window < k : yabai -m window --focus north; ${skhd} -k "escape" - mode_window < l : yabai -m window --focus east; ${skhd} -k "escape" - - mode_window < tab : yabai -m window --focus recent || yabai -m window --focus stack.recent; skhd -k "escape" - ralt - w : ${bash} ${skhdDir}/cycle-app.sh - - # focus next|prev window. - # https://github.com/koekeishiya/yabai/issues/203#issuecomment-1289940339 - ctrl+shift+alt - h : yabai -m query --spaces --space | ${jqbin} -re ".index" | xargs -I{} yabai -m query --windows --space {} | ${jqbin} -sre 'add | map(select(."is-minimized"==false)) | map(select(."has-ax-reference"==true)) | sort_by(.display, .frame.y, .frame.x, .id) | . as $array | length as $array_length | index(map(select(."has-focus"==true))) as $has_index | if $has_index > 0 then nth($has_index - 1).id else nth($array_length - 1).id end' | xargs -I{} yabai -m window --focus {} - ctrl+shift+alt - l : yabai -m query --spaces --space | ${jqbin} -re ".index" | xargs -I{} yabai -m query --windows --space {} | ${jqbin} -sre 'add | map(select(."is-minimized"==false)) | map(select(."has-ax-reference"==true)) | sort_by(.display, .frame.y, .frame.x, .id) | . as $array | length as $array_length | index(map(select(."has-focus"==true))) as $has_index | if $array_length - 1 > $has_index then nth($has_index + 1).id else nth(0).id end' | xargs -I{} yabai -m window --focus {} - - # toggle mission control in current space - ## show mission control preview of other spaces. - ## see: https://github.com/koekeishiya/yabai/issues/147 - ## for cliclick issue(move): https://github.com/BlueM/cliclick/issues/168#issuecomment-1575103405 - ## you might need to sleep shortly for consistency - ## yabai -m space --toggle mission-control && cliclick -r w:10 m:0,0 - # -r: restore initial position after move. - # w:250 wait for 250ms after each event. - # m:0,0, move to 0,0 coords. - # ctrl+shift+alt - g : yabai -m space --toggle mission-control && cliclick -w 250 -r m:0,0 m:1,1 w:250 - - # moving windows - mode_window_move < h : yabai -m window --warp west; skhd -k "escape" - mode_window_move < j : yabai -m window --warp south; skhd -k "escape" - mode_window_move < k : yabai -m window --warp north; skhd -k "escape" - mode_window_move < l : yabai -m window --warp east; skhd -k "escape" - - # move window to space — follow focus to destination - mode_window_move_space < 0x2F : yabai -m window --space recent; yabai -m space --focus recent; skhd -k "escape" - mode_window_move_space < p : yabai -m window --space prev; yabai -m space --focus prev; yabai -m window --focus recent || yabai -m window --focus stack.recent; skhd -k "escape"; - mode_window_move_space < n : yabai -m window --space next; yabai -m space --focus next; yabai -m window --focus recent || yabai -m window --focus stack.recent; skhd -k "escape"; - - mode_window_move_space < 1 : yabai -m window --space 1; yabai -m space --focus 1; yabai -m window --focus recent || yabai -m window --focus stack.recent; skhd -k "escape" - mode_window_move_space < 2 : yabai -m window --space 2; yabai -m space --focus 2; yabai -m window --focus recent || yabai -m window --focus stack.recent; skhd -k "escape" - mode_window_move_space < 3 : yabai -m window --space 3; yabai -m space --focus 3; yabai -m window --focus recent || yabai -m window --focus stack.recent; skhd -k "escape" - mode_window_move_space < 4 : yabai -m window --space 4; yabai -m space --focus 4; yabai -m window --focus recent || yabai -m window --focus stack.recent; skhd -k "escape" - mode_window_move_space < 5 : yabai -m window --space 5; yabai -m space --focus 5; yabai -m window --focus recent || yabai -m window --focus stack.recent; skhd -k "escape" - mode_window_move_space < 6 : yabai -m window --space 6; yabai -m space --focus 6; yabai -m window --focus recent || yabai -m window --focus stack.recent; skhd -k "escape" - mode_window_move_space < 7 : yabai -m window --space 7; yabai -m space --focus 7; yabai -m window --focus recent || yabai -m window --focus stack.recent; skhd -k "escape" - mode_window_move_space < 8 : yabai -m window --space 8; yabai -m space --focus 8; yabai -m window --focus recent || yabai -m window --focus stack.recent; skhd -k "escape" - mode_window_move_space < 9 : yabai -m window --space 9; yabai -m space --focus 9; yabai -m window --focus recent || yabai -m window --focus stack.recent; skhd -k "escape" - - # move window to display - mode_window_move_display < 1 : yabai -m window --display 1; yabai -m window --focus recent || yabai -m window --focus stack.recent; skhd -k "escape" - mode_window_move_display < 2 : yabai -m window --display 2; yabai -m window --focus recent || yabai -m window --focus stack.recent; skhd -k "escape" - mode_window_move_display < 3 : yabai -m window --display 3; yabai -m window --focus recent || yabai -m window --focus stack.recent; skhd -k "escape" - mode_window_move_display < 4 : yabai -m window --display 4; yabai -m window --focus recent || yabai -m window --focus stack.recent; skhd -k "escape" - # move window to next display or prev display - mode_window_move_display < p : yabai -m window --display prev; yabai -m window --focus recent || yabai -m window --focus stack.recent; skhd -k "escape" - mode_window_move_display < n : yabai -m window --display next; yabai -m window --focus recent || yabai -m window --focus stack.recent; skhd -k "escape" - - # stack windows - mode_window_stack < h : yabai -m window --stack west; skhd -k "escape" - mode_window_stack < j : yabai -m window --stack south; skhd -k "escape" - mode_window_stack < k : yabai -m window --stack north; skhd -k "escape" - mode_window_stack < l : yabai -m window --stack east; skhd -k "escape" - - mode_window_stack < u : yabai -m window --insert stack; skhd -k "escape" - - # resize windows — use shift to shrink - mode_window_resize < h : yabai -m window --resize left:-25:0 | yabai -m window --resize right:-25:0 - mode_window_resize < j : yabai -m window --resize bottom:0:25 | yabai -m window --resize top:0:25 - mode_window_resize < k : yabai -m window --resize top:0:-25 | yabai -m window --resize bottom:0:-25 - mode_window_resize < l : yabai -m window --resize right:25:0 | yabai -m window --resize left:25:0 - - ## >>>>>>>>>>>>>>>>> manage spaces - mode_space < i : yabai -m space --create; skhd -k "escape" - mode_space < x : yabai -m space --destroy; skhd -k "escape" - - mode_space < r : yabai -m space --rotate 270; skhd -k "escape" - mode_space < b : yabai -m space --balance; skhd -k "escape" - - # recent space. - ralt - tab : yabai -m space --focus recent - mode_space < tab : yabai -m space --focus recent - # mode_space < n : yabai -m space --focus recent - # next prev space. - # mode_space < l: yabai -m space --focus next; skhd -k "escape" - # mode_space < h : yabai -m space --focus prev; skhd -k "escape" - mode_space < n : ${bash} ${skhdDir}/space_cycle_next.sh; - mode_space < p : ${bash} ${skhdDir}/space_cycle_prev.sh; - ctrl+shift+alt - n : ${bash} ${skhdDir}/space_cycle_next.sh; - ctrl+shift+alt - p : ${bash} ${skhdDir}/space_cycle_prev.sh; - - # goto space by index - mode_space < 1 : yabai -m space --focus 1; skhd -k "escape" - mode_space < 2 : yabai -m space --focus 2; skhd -k "escape" - mode_space < 3 : yabai -m space --focus 3; skhd -k "escape" - mode_space < 4 : yabai -m space --focus 4; skhd -k "escape" - mode_space < 5 : yabai -m space --focus 5; skhd -k "escape" - mode_space < 6 : yabai -m space --focus 6; skhd -k "escape" - mode_space < 7 : yabai -m space --focus 7; skhd -k "escape" - mode_space < 8 : yabai -m space --focus 8; skhd -k "escape" - mode_space < 9 : yabai -m space --focus 9; skhd -k "escape" - - # shortcuts to focus space by index - ralt - 1 : yabai -m space --focus 1 - ralt - 2 : yabai -m space --focus 2 - ralt - 3 : yabai -m space --focus 3 - ralt - 4 : yabai -m space --focus 4 - - # change space layout - mode_space_arrange < s : yabai -m space --layout stack; skhd -k "escape"; ${bash} ${skhdDir}/notify.sh "Space layout" "Stack" - mode_space_arrange < f : yabai -m space --layout float; skhd -k "escape"; ${bash} ${skhdDir}/notify.sh "Space layout" "Float" - mode_space_arrange < t : yabai -m space --layout bsp; skhd -k "escape"; ${bash} ${skhdDir}/notify.sh "Space layout" "BSP" - - ## ========== manage display - mode_display < r : yabai --restart-service; skhd -k "escape" - # recent display - mode_display < tab : yabai -m display --focus recent - # mode_display < n : yabai -m display --focus recent; skhd -k "escape" - # next prev display - mode_display < n : ${bash} ${skhdDir}/display_cycle_next.sh; skhd -k "escape" - mode_display < p : ${bash} ${skhdDir}/display_cycle_prev.sh; skhd -k "escape" - ctrl+shift+alt - j : ${bash} ${skhdDir}/display_cycle_next.sh - ctrl+shift+alt - k : ${bash} ${skhdDir}/display_cycle_prev.sh - # go to display from 1 to 4 - mode_display < 1 : yabai -m display --focus 1; skhd -k "escape" - mode_display < 2 : yabai -m display --focus 2; skhd -k "escape" - mode_display < 3 : yabai -m display --focus 3; skhd -k "escape" - mode_display < 4 : yabai -m display --focus 4; skhd -k "escape" - # >>>>>>> end display - - ### other utils - - ralt - a : ${bash} ${skhdDir}/focus-app.sh "Ghostty"; - ralt - s : ${bash} ${skhdDir}/focus-app.sh "Google Chrome"; - ralt - d : ${bash} ${skhdDir}/focus-app.sh "Cursor"; - ''; - - # ========== scripts - "skhd/focus-app.sh".text = '' - #!${bashbin} - APP_NAME=$1 - set -x - wid=$(yabai -m query --windows | jq "[.[] | select(.app == \"$APP_NAME\") | .id][0]") - if [[ "$wid" -eq "0" ]]; then - echo "App not found" - else - yabai -m window --focus "$wid" - fi - ''; - - "skhd/space_focus_prev.sh".text = '' - #!${bashbin} - - if [[ $(yabai -m query --spaces --display | ${jqbin} '.[0]."has-focus"') == "false" ]]; then yabai -m space --focus prev; fi - ''; - - "skhd/space_focus_next.sh".text = '' - #!${bashbin} - - if [[ $(yabai -m query --spaces --display | ${jqbin} '.[-1]."has-focus"') == "false" ]]; then yabai -m space --focus next; fi - ''; - - "skhd/space_cycle_next.sh".text = '' - #!${bashbin} - - info=$(yabai -m query --spaces --display) - last=$(echo $info | jq '.[-1]."has-focus"') - - if [[ $last == "false" ]]; then - yabai -m space --focus next - else - yabai -m space --focus $(echo $info | jq '.[0].index') - fi - ''; - - "skhd/space_cycle_prev.sh".text = '' - #!${bashbin} - - info=$(yabai -m query --spaces --display) - first=$(echo $info | jq '.[0]."has-focus"') - - if [[ $first == "false" ]]; then - yabai -m space --focus prev - else - yabai -m space --focus $(echo $info | jq '.[-1].index') - fi - ''; - - "skhd/notify.sh".text = '' - #!${bashbin} - TITLE=$1 - MESSAGE=$2 - - osascript -e "display notification \"$MESSAGE\" with title \"$TITLE\"" - ''; - - "skhd/display_cycle_next.sh".text = '' - #!${bashbin} - # focus next display with yabai in cycle. - - current_display_index=$(yabai -m query --displays --display | jq '."index"') - total_displays=$(yabai -m query --displays | jq length) - next_display_index=$((current_display_index + 1)) - - if ((next_display_index > total_displays)); then - next_display_index=1 - fi - - yabai -m display --focus "''${next_display_index}" - ''; - - "skhd/display_cycle_prev.sh".text = '' - #!${bashbin} - # focus previous display with yabai in cycle. - - current_display_index=$(yabai -m query --displays --display | jq '."index"') - total_displays=$(yabai -m query --displays | jq length) - prev_display_index=$((current_display_index - 1)) - - if ((prev_display_index < 1)); then - prev_display_index=$total_displays - fi - - yabai -m display --focus "''${prev_display_index}" - ''; - - # focus the next window with the same app on different spaces and displays - # the app is selected by the current window's .app - # if no current win, just return. - "skhd/cycle-app.sh".text = '' - #!${bashbin} - - current_app=$(yabai -m query --windows --window | jq -r '.app') - current_app_id=$(yabai -m query --windows --window | jq -r '.id') - - if [[ -z "$current_app_id" ]]; then - echo "No current window" - return - fi - - # get all windows with the same app - windows=$(yabai -m query --windows | jq -r "[.[] | select(.app == \"$current_app\") | .id]") - # get the index of the current window - current_window_index=$(echo "$windows" | jq -r "index(\"$current_window_id\")") - # get the next window id - next_window_index=$((current_window_index + 1)) - # if the next window index is greater than the number of windows, wrap around - if ((next_window_index >= $(echo "$windows" | jq length))); then - next_window_index=0 - fi - # focus the next window by id - yabai -m window --focus $(echo "$windows" | jq -r ".[$next_window_index]") - ''; - }; + xdg.configFile = + let + jqbin = "${pkgs.jq}/bin/jq"; + bashbin = "${pkgs.bash}/bin/bash"; + skhdDir = "${config.xdg.configHome}/skhd"; + skhd = "${pkgs.skhd}/bin/skhd"; + bash = "${pkgs.bash}/bin/bash"; + in + { + "skhd/skhdrc".text = '' + # https://github.com/nikhgupta/dotfiles/blob/c545755f782cd1cee90c7a7307ff17f730c18e09/config/skhd/skhdrc + # @see key code: https://github.com/koekeishiya/skhd/issues/1 + # see: https://github.com/solomonbroadbent/dotfiles/blob/2f6c660c15e2050785ed1f08aaf89c199ffacc3d/.skhdrc#L1 + # see keyboard codes: https://cloud.githubusercontent.com/assets/6175959/18551554/35137fc6-7b59-11e6-81a0-bef19ed5db5e.png + # powerfull mode declaration + :: default + + :: mode_window @ + :: mode_window_move @ + :: mode_window_move_space @ + :: mode_window_move_display @ + :: mode_window_toggle @ + :: mode_window_stack @ + :: mode_window_resize @ + + :: mode_space @ + :: mode_space_arrange @ + + :: mode_display @ + + # define escape as exit from every mode + mode_window < ctrl - space ; default + mode_window_move < ctrl - space ; default + mode_window_move_space < ctrl - space ; default + mode_window_move_display < ctrl - space ; default + mode_window_toggle < ctrl - space ; default + mode_window_stack < ctrl - space ; default + mode_window_resize < ctrl - space ; default + mode_space < ctrl - space ; default + mode_space_arrange < ctrl - space ; default + mode_display < ctrl - space ; default + ## --- escape, easy exit + mode_window < escape ; default + mode_window_move < escape ; default + mode_window_move_space < escape ; default + mode_window_move_display < escape ; default + mode_window_toggle < escape ; default + mode_window_stack < escape ; default + mode_window_resize < escape ; default + mode_space < escape ; default + mode_space_arrange < escape ; default + mode_display < escape ; default + + # define mode entry + ctrl+shift+alt - space ; default + ctrl+shift+alt - w ; mode_window + mode_window < m ; mode_window_move + mode_window_move < s ; mode_window_move_space + mode_window_move < d ; mode_window_move_display + mode_window < t ; mode_window_toggle + mode_window < s ; mode_window_stack + mode_window < r ; mode_window_resize + + ctrl+shift+alt - s ; mode_space + mode_space < a ; mode_space_arrange + + ctrl+shift+alt - d ; mode_display + + ## ============== manage windows + mode_window < x : yabai -m window --close; skhd -k "ctrl - space" + mode_window < return : yabai -m window --toggle zoom-fullscreen; skhd -k "ctrl - space" + # current window will be in float state, out control of current space layout. + mode_window_toggle < f : yabai -m window --toggle float; skhd -k "ctrl - space" + # make current window stick to current space layout. + mode_window_toggle < a : yabai -m window --toggle sticky; skhd -k "ctrl - space" + + mode_window < h : yabai -m window --focus west; ${skhd} -k "ctrl - space" + mode_window < j : yabai -m window --focus south; ${skhd} -k "ctrl - space" + mode_window < k : yabai -m window --focus north; ${skhd} -k "ctrl - space" + mode_window < l : yabai -m window --focus east; ${skhd} -k "ctrl - space" + + # focus recent window + ralt - r : yabai -m window --focus recent + mode_window < tab : yabai -m window --focus recent || yabai -m window --focus stack.recent; skhd -k "ctrl - space" + ralt - e : ${bash} ${skhdDir}/cycle-app.sh --focus prev + ralt - w : ${bash} ${skhdDir}/cycle-app.sh --focus next + + # focus next|prev window. + # https://github.com/koekeishiya/yabai/issues/203#issuecomment-1289940339 + ctrl+shift+alt - h : yabai -m query --spaces --space | ${jqbin} -re ".index" | xargs -I{} yabai -m query --windows --space {} | ${jqbin} -sre 'add | map(select(."is-minimized"==false)) | map(select(."has-ax-reference"==true)) | sort_by(.display, .frame.y, .frame.x, .id) | . as $array | length as $array_length | index(map(select(."has-focus"==true))) as $has_index | if $has_index > 0 then nth($has_index - 1).id else nth($array_length - 1).id end' | xargs -I{} yabai -m window --focus {} + ctrl+shift+alt - l : yabai -m query --spaces --space | ${jqbin} -re ".index" | xargs -I{} yabai -m query --windows --space {} | ${jqbin} -sre 'add | map(select(."is-minimized"==false)) | map(select(."has-ax-reference"==true)) | sort_by(.display, .frame.y, .frame.x, .id) | . as $array | length as $array_length | index(map(select(."has-focus"==true))) as $has_index | if $array_length - 1 > $has_index then nth($has_index + 1).id else nth(0).id end' | xargs -I{} yabai -m window --focus {} + + # toggle mission control in current space + ## show mission control preview of other spaces. + ## see: https://github.com/koekeishiya/yabai/issues/147 + ## for cliclick issue(move): https://github.com/BlueM/cliclick/issues/168#issuecomment-1575103405 + ## you might need to sleep shortly for consistency + ## yabai -m space --toggle mission-control && cliclick -r w:10 m:0,0 + # -r: restore initial position after move. + # w:250 wait for 250ms after each event. + # m:0,0, move to 0,0 coords. + # ctrl+shift+alt - g : yabai -m space --toggle mission-control && cliclick -w 250 -r m:0,0 m:1,1 w:250 + + # moving windows + mode_window_move < h : yabai -m window --warp west; skhd -k "ctrl - space" + mode_window_move < j : yabai -m window --warp south; skhd -k "ctrl - space" + mode_window_move < k : yabai -m window --warp north; skhd -k "ctrl - space" + mode_window_move < l : yabai -m window --warp east; skhd -k "ctrl - space" + + # move window to space — follow focus to destination + mode_window_move_space < r : yabai -m window --space recent; yabai -m space --focus recent; skhd -k "ctrl - space" + mode_window_move_space < p : yabai -m window --space prev; yabai -m space --focus prev; skhd -k "ctrl - space" + mode_window_move_space < n : yabai -m window --space next; yabai -m space --focus next; skhd -k "ctrl - space" + + mode_window_move_space < 1 : yabai -m window --space 1; yabai -m space --focus 1; skhd -k "ctrl - space" + mode_window_move_space < 2 : yabai -m window --space 2; yabai -m space --focus 2; skhd -k "ctrl - space" + mode_window_move_space < 3 : yabai -m window --space 3; yabai -m space --focus 3; skhd -k "ctrl - space" + mode_window_move_space < 4 : yabai -m window --space 4; yabai -m space --focus 4; skhd -k "ctrl - space" + mode_window_move_space < 5 : yabai -m window --space 5; yabai -m space --focus 5; skhd -k "ctrl - space" + mode_window_move_space < 6 : yabai -m window --space 6; yabai -m space --focus 6; skhd -k "ctrl - space" + mode_window_move_space < 7 : yabai -m window --space 7; yabai -m space --focus 7; skhd -k "ctrl - space" + mode_window_move_space < 8 : yabai -m window --space 8; yabai -m space --focus 8; skhd -k "ctrl - space" + mode_window_move_space < 9 : yabai -m window --space 9; yabai -m space --focus 9; skhd -k "ctrl - space" + + # move window to display + mode_window_move_display < 1 : yabai -m window --display 1; skhd -k "ctrl - space" + mode_window_move_display < 2 : yabai -m window --display 2; skhd -k "ctrl - space" + mode_window_move_display < 3 : yabai -m window --display 3; skhd -k "ctrl - space" + mode_window_move_display < 4 : yabai -m window --display 4; skhd -k "ctrl - space" + # move window to next display or prev display + mode_window_move_display < p : yabai -m window --display prev; skhd -k "ctrl - space" + mode_window_move_display < n : yabai -m window --display next; skhd -k "ctrl - space" + + # stack windows + mode_window_stack < h : yabai -m window --stack west; skhd -k "ctrl - space" + mode_window_stack < j : yabai -m window --stack south; skhd -k "ctrl - space" + mode_window_stack < k : yabai -m window --stack north; skhd -k "ctrl - space" + mode_window_stack < l : yabai -m window --stack east; skhd -k "ctrl - space" + + mode_window_stack < u : yabai -m window --insert stack; skhd -k "ctrl - space" + + # resize windows — use shift to shrink + mode_window_resize < h : yabai -m window --resize left:-25:0 | yabai -m window --resize right:-25:0 + mode_window_resize < j : yabai -m window --resize bottom:0:25 | yabai -m window --resize top:0:25 + mode_window_resize < k : yabai -m window --resize top:0:-25 | yabai -m window --resize bottom:0:-25 + mode_window_resize < l : yabai -m window --resize right:25:0 | yabai -m window --resize left:25:0 + + ## >>>>>>>>>>>>>>>>> manage spaces + mode_space < i : yabai -m space --create; skhd -k "ctrl - space" + mode_space < x : yabai -m space --destroy; skhd -k "ctrl - space" + + mode_space < r : yabai -m space --rotate 270; skhd -k "ctrl - space" + mode_space < b : yabai -m space --balance; skhd -k "ctrl - space" + + # recent space. + ralt - tab : yabai -m space --focus recent + mode_space < tab : yabai -m space --focus recent + # mode_space < n : yabai -m space --focus recent + # next prev space. + # mode_space < l: yabai -m space --focus next; skhd -k "ctrl - space" + # mode_space < h : yabai -m space --focus prev; skhd -k "ctrl - space" + mode_space < n : ${bash} ${skhdDir}/space_cycle_next.sh; + mode_space < p : ${bash} ${skhdDir}/space_cycle_prev.sh; + ctrl+shift+alt - n : ${bash} ${skhdDir}/space_cycle_next.sh; + ctrl+shift+alt - p : ${bash} ${skhdDir}/space_cycle_prev.sh; + + # goto space by index + mode_space < 1 : yabai -m space --focus 1; skhd -k "ctrl - space" + mode_space < 2 : yabai -m space --focus 2; skhd -k "ctrl - space" + mode_space < 3 : yabai -m space --focus 3; skhd -k "ctrl - space" + mode_space < 4 : yabai -m space --focus 4; skhd -k "ctrl - space" + mode_space < 5 : yabai -m space --focus 5; skhd -k "ctrl - space" + mode_space < 6 : yabai -m space --focus 6; skhd -k "ctrl - space" + mode_space < 7 : yabai -m space --focus 7; skhd -k "ctrl - space" + mode_space < 8 : yabai -m space --focus 8; skhd -k "ctrl - space" + mode_space < 9 : yabai -m space --focus 9; skhd -k "ctrl - space" + + # shortcuts to focus space by index + ralt - 1 : yabai -m space --focus 1 + ralt - 2 : yabai -m space --focus 2 + ralt - 3 : yabai -m space --focus 3 + ralt - 4 : yabai -m space --focus 4 + + # change space layout + mode_space_arrange < s : yabai -m space --layout stack; skhd -k "ctrl - space"; ${bash} ${skhdDir}/notify.sh "Space layout" "Stack" + mode_space_arrange < f : yabai -m space --layout float; skhd -k "ctrl - space"; ${bash} ${skhdDir}/notify.sh "Space layout" "Float" + mode_space_arrange < t : yabai -m space --layout bsp; skhd -k "ctrl - space"; ${bash} ${skhdDir}/notify.sh "Space layout" "BSP" + + ## ========== manage display + mode_display < r : yabai --restart-service; skhd -k "ctrl - space" + # recent display + mode_display < tab : yabai -m display --focus recent + # mode_display < n : yabai -m display --focus recent; skhd -k "ctrl - space" + # next prev display + mode_display < n : ${bash} ${skhdDir}/display_cycle_next.sh; skhd -k "ctrl - space" + mode_display < p : ${bash} ${skhdDir}/display_cycle_prev.sh; skhd -k "ctrl - space" + ctrl+shift+alt - j : ${bash} ${skhdDir}/display_cycle_next.sh + ctrl+shift+alt - k : ${bash} ${skhdDir}/display_cycle_prev.sh + # go to display from 1 to 4 + mode_display < 1 : yabai -m display --focus 1; skhd -k "ctrl - space" + mode_display < 2 : yabai -m display --focus 2; skhd -k "ctrl - space" + mode_display < 3 : yabai -m display --focus 3; skhd -k "ctrl - space" + mode_display < 4 : yabai -m display --focus 4; skhd -k "ctrl - space" + # >>>>>>> end display + + ### other utils + + ralt - a : ${bash} ${skhdDir}/focus-app.sh "kitty"; + ralt - s : ${bash} ${skhdDir}/focus-app.sh "Google Chrome"; + ralt - d : ${bash} ${skhdDir}/focus-app.sh "Cursor"; + ''; + + # ========== scripts + "skhd/focus-app.sh".text = '' + #!${bashbin} + APP_NAME=$1 + set -x + wid=$(yabai -m query --windows | jq "[.[] | select(.app == \"$APP_NAME\") | .id][0]") + if [[ "$wid" -eq "0" ]]; then + echo "App not found" + else + yabai -m window --focus "$wid" + fi + ''; + + "skhd/space_focus_prev.sh".text = '' + #!${bashbin} + + if [[ $(yabai -m query --spaces --display | ${jqbin} '.[0]."has-focus"') == "false" ]]; then yabai -m space --focus prev; fi + ''; + + "skhd/space_focus_next.sh".text = '' + #!${bashbin} + + if [[ $(yabai -m query --spaces --display | ${jqbin} '.[-1]."has-focus"') == "false" ]]; then yabai -m space --focus next; fi + ''; + + "skhd/space_cycle_next.sh".text = '' + #!${bashbin} + + info=$(yabai -m query --spaces --display) + last=$(echo $info | jq '.[-1]."has-focus"') + + if [[ $last == "false" ]]; then + yabai -m space --focus next + else + yabai -m space --focus $(echo $info | jq '.[0].index') + fi + ''; + + "skhd/space_cycle_prev.sh".text = '' + #!${bashbin} + + info=$(yabai -m query --spaces --display) + first=$(echo $info | jq '.[0]."has-focus"') + + if [[ $first == "false" ]]; then + yabai -m space --focus prev + else + yabai -m space --focus $(echo $info | jq '.[-1].index') + fi + ''; + + "skhd/notify.sh".text = '' + #!${bashbin} + TITLE=$1 + MESSAGE=$2 + + osascript -e "display notification \"$MESSAGE\" with title \"$TITLE\"" + ''; + + "skhd/display_cycle_next.sh".text = '' + #!${bashbin} + # focus next display with yabai in cycle. + + current_display_index=$(yabai -m query --displays --display | jq '."index"') + total_displays=$(yabai -m query --displays | jq length) + next_display_index=$((current_display_index + 1)) + + if ((next_display_index > total_displays)); then + next_display_index=1 + fi + + yabai -m display --focus "''${next_display_index}" + ''; + + "skhd/display_cycle_prev.sh".text = '' + #!${bashbin} + # focus previous display with yabai in cycle. + + current_display_index=$(yabai -m query --displays --display | jq '."index"') + total_displays=$(yabai -m query --displays | jq length) + prev_display_index=$((current_display_index - 1)) + + if ((prev_display_index < 1)); then + prev_display_index=$total_displays + fi + + yabai -m display --focus "''${prev_display_index}" + ''; + + # focus the next window with the same app on different spaces and displays + # the app is selected by the current window's .app + # if no current win, just return. + "skhd/cycle-app.sh".text = '' + #!${bashbin} + +while [[ "$#" -gt 0 ]] + do + case $1 in + -f|--focus) + if [ "$2" = "prev" ] + then + pos=-1 + else + pos=1 + fi + ;; + esac + shift + done + +pos=''${pos:-1} + +focus="$(yabai -m query --windows | \ + jq -e --argjson pos $pos '(.[] | select(."has-focus")) as {$id, $app} + | map( select( .app==$app and ((."is-hidden" or ."is-minimized") | not) ) ) + | sort_by(.space, .frame.x, .frame.y) + | map(.id) + | .[(index($id)+($pos))%length]' + )" + +yabai -m window --focus "$focus" + ''; + }; } diff --git a/nix/hm/tmux.nix b/nix/hm/tmux.nix index 82451d31..15dba40f 100644 --- a/nix/hm/tmux.nix +++ b/nix/hm/tmux.nix @@ -10,6 +10,11 @@ in { ".tmux/bin".source = ../../conf/tmux/bin; ".tmux/nix-bin/zoxide-projects.sh".text = '' + current_session=$(tmux display-message -p '#{session_name}') + if [[ $current_session == "FLOAT" ]]; then + exit + fi + if [[ $# -eq 1 ]]; then selected=$1 else @@ -218,8 +223,9 @@ in { bind C-p run "${config.home.homeDirectory}/.tmux/bin/pane.sh switch" ## start new session from folder. bind y popup -E -w 80% -h 60% "${pkgs.bash}/bin/bash ${config.home.homeDirectory}/.tmux/nix-bin/zoxide-projects.sh" - bind f run "${config.home.homeDirectory}/.tmux/bin/tmux-scratch-toggle.tmux" - bind C-f run "${bash} ${config.home.homeDirectory}/.tmux/bin/tmux-scratch-toggle.tmux toggle" + bind-key -n M-f run "${config.home.homeDirectory}/.tmux/bin/tmux-scratch-toggle.tmux" + ## M-g to open popup to run tig on current directory + bind-key -n M-g popup -E -w 95% -h 98% -d "#{pane_current_path}" "lazygit" bind : run "${config.home.homeDirectory}/.tmux/bin/command.sh" bind & run "${config.home.homeDirectory}/.tmux/bin/process.sh" @@ -262,8 +268,8 @@ in { # =============================================== ## UI - set -g pane-border-status bottom - set -g status-interval 1 + set -g pane-border-status top + set -g status-interval 10 set -g status on set -g status-left-length 100 set -g status-right-length 300 @@ -271,18 +277,18 @@ in { set-window-option -g status-position top set -g message-style fg=black,bg=blue set -g message-command-style fg=black,bg=blue - set -g status-style bg=default,fg=yellow - set -g pane-border-style bg=default,fg=yellow - set -g pane-active-border-style bg=default,fg=blue - set -g display-panes-colour black - set -g display-panes-active-colour cyan + # set -g status-style bg=default,fg=yellow + # set -g pane-border-style bg=default,fg=yellow + # set -g pane-active-border-style bg=default,fg=blue + # set -g display-panes-colour black + # set -g display-panes-active-colour cyan #+--- Bars ---+ set -g status-left "#[bold] #S " set -g status-right "#[bold] #h " #+--- Windows ---+ - set -g window-status-format " #I·#W#{?window_zoomed_flag,##Z,}#{?window_end_flag, , }" - set -g window-status-current-format "#[bg=blue,fg=black,bold] #I·#W#{?window_zoomed_flag,##Z,}#{?window_end_flag, , }" - set -g window-status-separator "#[fg=colour8]│" + set -g window-status-format "#I:#W#F#{?window_end_flag, , }" + set -g window-status-current-format "#[bold][#I:#W]#F#{?window_end_flag, , }" + # set -g window-status-separator "#[fg=colour8]│" # ========== End UI ''; }; diff --git a/nix/home.nix b/nix/home.nix index 11e33812..75d4ef5a 100644 --- a/nix/home.nix +++ b/nix/home.nix @@ -5,13 +5,15 @@ username, useGlobalPkgs ? false, ... -}: let - locals.packages = with pkgs; +}: +let + locals.packages = + with pkgs; [ ## Nix cachix # nix formatter - alejandra + nixfmt-rfc-style nixd # nix-health # git-fuzzy @@ -29,6 +31,7 @@ ## man page tldr tlrc sd + difftastic ## image view support imagemagick luajitPackages.magick @@ -44,7 +47,8 @@ # linux packages xclip ]; -in { +in +{ nixpkgs = lib.mkIf (!useGlobalPkgs) { config = { # obsidian for example have unfree license. @@ -59,10 +63,7 @@ in { # Home Manager needs a bit of information about you and the paths it should # manage. username = "${username}"; - homeDirectory = - if pkgs.stdenv.isLinux - then "/home/${username}" - else "/Users/${username}"; + homeDirectory = if pkgs.stdenv.isLinux then "/home/${username}" else "/Users/${username}"; # This value determines the Home Manager release that your configuration is # compatible with. This helps avoid breakage when a new Home Manager release # introduces backwards incompatible changes. @@ -153,10 +154,12 @@ in { ./hm/skhd.nix ./hm/yabai.nix ./hm/dark-mode-notify.nix + ./hm/lazygit.nix ]; # Let Home Manager install and manage itself. programs = { + man.generateCaches = false; home-manager.enable = true; # Direnv integration for flakes direnv = {