Compare commits

...

5 commits

Author SHA1 Message Date
bed0f97bd7 feat(shell): add sa alias for sl amend 2024-09-04 19:12:55 +01:00
3f2964cfcb feat(vim): display clippy diagnostics on save 2024-09-04 19:11:57 +01:00
9ff18b1688 feat(vim): setup ivy.nvim in the config
This was an update that now it does not get configured by default you need to
call the `setup` function to make it work.

See: https://github.com/AdeAttwood/ivy.nvim/pull/81
2024-09-04 19:10:24 +01:00
7603040373 feat(bin): update pf script to use wezterm tabs
When the move from tmux I can no longer use pf to start processes from a
Procfile in a new session. This will do basically the same if we are not in a
tmux session and start all the processes in wezterm tabs in the same workspace.
This currently does not support closing the tabs, if this needs to be done you
can kill the hole terminal and start it again.

This also updates the script so you can pass in a file and it will use that
file. Previously it was hardcoded to `Procfile.dev`, now this is the default
however, can be overridden
2024-09-04 19:06:39 +01:00
6b939f0486 feat(term): move to wezterm mux from tmux
So this is the first commit where we are starting to migrate from tmux.
Right now I'm not sure how this will go, every other attempt has not
lasted very long.

This does support all the features I am using in tmux though. TBH most
of the stuff in the tmux.conf wezterm does by default. For example, the
pain numbers start at 1 not 0.

This implements a fork of tmux navigation, the plugin I have been using
in vim since like.... day one.
2024-09-04 18:20:25 +01:00
6 changed files with 278 additions and 21 deletions

View file

@ -18,43 +18,83 @@
[]
(string/join "/" (map #(.toString %) (take 2 (reverse(fs/components (fs/cwd)))))))
(defn parse-procfile
(defn parse-procfile
"Parses a procfile file and returns a list of [name command] pairs."
[]
(map #(string/split % #":\s+") (string/split (slurp "Procfile.dev") #"\n" )))
[file]
(map #(string/split % #":\s+") (string/split (slurp file) #"\n" )))
(defn has-session?
(defn has-tmux-session?
"Tests to see if a session already exists with a given name."
[session-name]
(string/includes? (:out (shell {:out :string} "tmux list-sessions")) session-name))
(defn has-window?
(defn has-tmux-window?
"Tests to see if a window already exists within a tmux session."
[session-name window-name]
(string/includes? (:out (shell {:out :string} (format "tmux list-windows -t '%s'" session-name))) window-name))
(defn create-window
(defn create-tmux-window
"Creates a new tmux window in a session if it dose not already exists. Then
it will run any commands that are passed inside the new window."
[project name & commands]
(when-not (has-window? project name)
(when-not (has-tmux-window? project name)
(shell (format "tmux new-window -t '%s' -n '%s'" project name))
(doseq [command commands]
(shell (format "tmux send-keys -t %s:'%s' '%s' C-m" project name command)))))
(defn command-start [_]
(when (not (fs/exists? "Procfile.dev"))
(println "No Procfile.dev found in the current directory")
(System/exit 0))
(when (not (has-session? (current-project-name)))
(defn tmux-start [file]
(when (not (has-tmux-session? (current-project-name)))
(shell (format "tmux new-session -d -c %s -s '%s'" (fs/cwd) (current-project-name))))
(doseq [[name command] (parse-procfile)]
(create-window (current-project-name) name command)))
(doseq [[name command] (parse-procfile file)]
(create-tmux-window (current-project-name) name command)))
(defn is-in-tmux?
"Tests to see if we are in a tmux session or not."
[]
(not (nil? (System/getenv "TMUX"))))
(defn has-wezterm-pane?
"Tests to see if a wezterm pane already exists."
[name]
(string/includes? (:out (shell {:out :string} "wezterm cli list")) (format "pf: %s" name)))
(defn create-wezterm-pane
"Create a new wezterm pane and spawn a command in it."
[name command]
(let [pane-id (:out (shell {:out :string} (format "wezterm cli spawn --cwd %s" (fs/cwd))))]
(shell (format "wezterm cli set-tab-title --pane-id %s 'pf: %s'" pane-id name))
(shell {:in command} (format "wezterm cli send-text --pane-id %s" pane-id))
(shell {:in "\n"} (format "wezterm cli send-text --pane-id %s" pane-id))))
(defn wezterm-start [file]
(let [pane-id (System/getenv "WEZTERM_PANE")]
(doseq [[name command] (parse-procfile file)]
(when (not (has-wezterm-pane? name))
(create-wezterm-pane name command)))
(shell (format "wezterm cli activate-pane --pane-id %s" pane-id))))
(defn is-in-wezterm?
"Tests to see if we are in a wezterm session or not."
[]
(not (nil? (System/getenv "WEZTERM_PANE"))))
(defn command-start [m]
(let [file (get-in m [:opts :file] "Procfile.dev")]
(when (not (fs/exists? file))
(println "No Procfile.dev found in the current directory")
(System/exit 0))
(cond
(is-in-tmux?) (tmux-start file)
(is-in-wezterm?) (wezterm-start file)
:else (println "Unable to spawn processes in the current environment"))
(System/exit 0)))
(defn command-stop [_]
(when (has-session? (current-project-name))
(when (has-tmux-session? (current-project-name))
(shell (format "tmux kill-session -t '%s'" (current-project-name)))))
(defn command-restart [args]
@ -71,7 +111,7 @@
(println ""))
(def command-table
[{:cmds ["start"] :fn command-start}
[{:cmds ["start"] :fn command-start :opts {:file "Procfile.dev"}}
{:cmds ["stop"] :fn command-stop}
{:cmds ["restart"] :fn command-restart}
{:cmds [] :fn help}])

View file

@ -3,6 +3,7 @@
alias s="\\sl"
alias sl="\\sl log --pager never --remote -r '.::top() or last(::., 40)'"
alias sc="\\sl addremove . && \\sl commit -iv"
alias sa="\\sl addremove . && \\sl amend -iv"
alias sd="\\sl diff"
alias ss="\\sl status"
alias sco="\\sl log -r 'heads(draft())' | fzf --ansi | cut -d' ' -f3 | xargs \\sl goto"

View file

@ -0,0 +1,11 @@
-- Set up ivy.nvim
-- See: https://github.com/AdeAttwood/ivy.nvim
require('ivy').setup {
backends = {
"ivy.backends.buffers",
"ivy.backends.files",
"ivy.backends.lines",
"ivy.backends.lsp-workspace-symbols",
"ivy.backends.rg",
},
}

View file

@ -20,7 +20,15 @@ local servers = {
cmd = { "bundle", "exec", "solargraph", "stdio" },
},
-- Rust
rust_analyzer = {},
rust_analyzer = {
settings = {
["rust-analyzer"] = {
checkOnSave = {
command = "clippy",
},
},
},
},
-- Lua for the vim config and plugin dev
lua_ls = {
settings = {

View file

@ -0,0 +1,112 @@
" Maps <C-h/j/k/l> to switch vim splits in the given direction. If there are
" no more windows in that direction, forwards the operation to wezterm.
" Additionally, <C-\> toggles between last active vim splits/wezterm panes.
if exists("g:loaded_wezterm_navigator") || &cp || v:version < 700
finish
endif
let g:loaded_wezterm_navigator = 1
function! s:DirectionToKey(direction)
if a:direction ==# 'Up'
return 'k'
elseif a:direction ==# 'Down'
return 'j'
elseif a:direction ==# 'Left'
return 'h'
elseif a:direction ==# 'Right'
return 'l'
else
return 'p'
endif
endfunction
function! s:VimNavigate(direction)
try
execute 'wincmd ' . s:DirectionToKey(a:direction)
catch
echohl ErrorMsg | echo 'E11: Invalid in command-line window; <CR> executes, CTRL-C quits: wincmd k' | echohl None
endtry
endfunction
if !get(g:, 'wezterm_navigator_no_mappings', 0)
nnoremap <silent> <c-h> :<C-U>WestermNavigateLeft<cr>
nnoremap <silent> <c-j> :<C-U>WestermNavigateDown<cr>
nnoremap <silent> <c-k> :<C-U>WestermNavigateUp<cr>
nnoremap <silent> <c-l> :<C-U>WestermNavigateRight<cr>
nnoremap <silent> <c-\> :<C-U>WestermNavigatePrevious<cr>
endif
if empty($WEZTERM_PANE)
command! WestermNavigateLeft call s:VimNavigate('h')
command! WestermNavigateDown call s:VimNavigate('j')
command! WestermNavigateUp call s:VimNavigate('k')
command! WestermNavigateRight call s:VimNavigate('l')
command! WestermNavigatePrevious call s:VimNavigate('p')
finish
endif
command! WestermNavigateLeft call s:WeztermAwareNavigate('Left')
command! WestermNavigateDown call s:WeztermAwareNavigate('Down')
command! WestermNavigateUp call s:WeztermAwareNavigate('Up')
command! WestermNavigateRight call s:WeztermAwareNavigate('Right')
command! WestermNavigatePrevious call s:WeztermAwareNavigate('Prev')
let s:pane_position_from_direction = {'h': 'left', 'j': 'bottom', 'k': 'top', 'l': 'right'}
function! s:weztermOrTmateExecutable()
return "wezterm"
endfunction
function! s:weztermSocket()
" The socket path is the first value in the comma-separated list of $wezterm.
return split($wezterm, ',')[0]
endfunction
let s:wezterm_is_last_pane = 0
augroup wezterm_navigator
au!
autocmd WinEnter * let s:wezterm_is_last_pane = 0
augroup END
function! s:NeedsVitalityRedraw()
return exists('g:loaded_vitality') && v:version < 704 && !has("patch481")
endfunction
function! s:ShouldForwardNavigationBackToWezterm(wezterm_last_pane, at_tab_page_edge)
endfunction
function! s:ShouldForwardNavigationBackToWezterm(wezterm_last_pane, at_tab_page_edge)
return a:wezterm_last_pane || a:at_tab_page_edge
endfunction
function! s:WeztermCommand(args)
let cmd = 'wezterm cli ' . a:args
let l:x=&shellcmdflag
let retval=system(cmd)
let &shellcmdflag=l:x
return retval
endfunction
function! s:WeztermAwareNavigate(direction)
let nr = winnr()
let wezterm_last_pane = (a:direction == 'p' && s:wezterm_is_last_pane)
if !wezterm_last_pane
call s:VimNavigate(a:direction)
endif
let at_tab_page_edge = (nr == winnr())
" Forward the switch panes command to wezterm if:
" a) we're toggling between the last wezterm pane;
" b) we tried switching windows in vim but it didn't have effect.
if s:ShouldForwardNavigationBackToWezterm(wezterm_last_pane, at_tab_page_edge)
let args = 'activate-pane-direction ' . shellescape(a:direction)
silent call s:WeztermCommand(args)
if s:NeedsVitalityRedraw()
redraw!
endif
let s:wezterm_is_last_pane = 1
else
let s:wezterm_is_last_pane = 0
endif
endfunction

View file

@ -1,5 +1,26 @@
local wezterm = require "wezterm"
local scheme = wezterm.get_builtin_color_schemes()
local nord = scheme["nord"]
local function vim_pass_though_action(config)
return {
key = config.key,
mods = config.mods,
action = wezterm.action_callback(function(win, pane)
local process_name = pane:get_foreground_process_name()
-- If we are in vim then we want to send the key to go to the net pain
if string.match(process_name, "vim") or string.match(process_name, "emacs") then
win:perform_action({ SendKey = { key = config.key, mods = config.mods } }, pane)
return
end
win:perform_action({ ActivatePaneDirection = config.direction }, pane)
end),
}
end
return {
-- Use a sexy terminal font with ligatures.
-- You will need to install the beta version of the font to get the ligatures
@ -9,7 +30,36 @@ return {
},
-- The nord theme to fit with everyting else
color_scheme = 'nord',
color_scheme = "nord",
colors = {
tab_bar = {
background = nord.background,
active_tab = {
bg_color = "#88c0d0", -- nord.background,
fg_color = nord.background,
},
inactive_tab = {
bg_color = nord.background,
fg_color = nord.foreground,
},
inactive_tab_hover = {
bg_color = "#4c566a",
fg_color = nord.foreground,
italic = false,
},
new_tab = {
bg_color = nord.background,
fg_color = nord.foreground,
},
new_tab_hover = {
bg_color = "#4c566a",
fg_color = nord.foreground,
italic = false,
},
},
},
use_fancy_tab_bar = false,
-- Give the font some more line height, just makes thinks look a bit nicer
line_height = 1.4,
@ -23,7 +73,7 @@ return {
audible_bell = "Disabled",
-- Have a really clean UI when there is only one tab open
hide_tab_bar_if_only_one_tab = true,
hide_tab_bar_if_only_one_tab = false,
-- Disabled all the padding, this makes vim look a lot nicer when all the
-- window bars go to the edges of the terminal
@ -31,7 +81,11 @@ return {
warn_about_missing_glyphs = false,
enable_wayland = false,
tab_bar_at_bottom = true,
enable_wayland = true,
leader = { key = "b", mods = "CTRL" },
keys = {
-- Bind <CTRL-Backspace> to <CTRL-w> to `werase` in bash. This is to keep
@ -43,5 +97,36 @@ return {
key = "Backspace",
action = wezterm.action.SendKey { mods = "CTRL", key = "w" },
},
-- tmux features to complete
-- - Fuzzy finding / switching between pains
-- - Prompt search back
-- - Find out the copy and pasteing story
-- - Is there a "copy mode" like in tmux?
-- - Nvim split navigation intergation
-- Pane navigation like vim, this is what I have been using in tmux and how
-- the finger move
vim_pass_though_action { key = "h", mods = "CTRL", direction = "Left" },
vim_pass_though_action { key = "j", mods = "CTRL", direction = "Down" },
vim_pass_though_action { key = "k", mods = "CTRL", direction = "Up" },
vim_pass_though_action { key = "l", mods = "CTRL", direction = "Right" },
-- Split panes with the tmux keys. Again this alrady uses the same
-- directory as the current pane. Again no shinanigans needed
{ key = "s", mods = "LEADER", action = wezterm.action { SplitVertical = { domain = "CurrentPaneDomain" } } },
{ key = "v", mods = "LEADER", action = wezterm.action { SplitHorizontal = { domain = "CurrentPaneDomain" } } },
-- Tab navigation via numbers. This already starts a 1 so we don't need
-- todo any shinangans to make that work better
{ key = "1", mods = "LEADER", action = wezterm.action { ActivateTab = 0 } },
{ key = "2", mods = "LEADER", action = wezterm.action { ActivateTab = 1 } },
{ key = "3", mods = "LEADER", action = wezterm.action { ActivateTab = 2 } },
{ key = "4", mods = "LEADER", action = wezterm.action { ActivateTab = 3 } },
{ key = "5", mods = "LEADER", action = wezterm.action { ActivateTab = 4 } },
{ key = "6", mods = "LEADER", action = wezterm.action { ActivateTab = 5 } },
{ key = "7", mods = "LEADER", action = wezterm.action { ActivateTab = 6 } },
{ key = "8", mods = "LEADER", action = wezterm.action { ActivateTab = 7 } },
{ key = "9", mods = "LEADER", action = wezterm.action { ActivateTab = 8 } },
},
}