Compare commits

..

No commits in common. "bed0f97bd7d29ab6223e07bb56d1312758ced79f" and "ac75f42cfbb6f0d39f90d46e12d165992666b10a" have entirely different histories.

6 changed files with 21 additions and 278 deletions

View file

@ -18,83 +18,43 @@
[] []
(string/join "/" (map #(.toString %) (take 2 (reverse(fs/components (fs/cwd))))))) (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." "Parses a procfile file and returns a list of [name command] pairs."
[file] []
(map #(string/split % #":\s+") (string/split (slurp file) #"\n" ))) (map #(string/split % #":\s+") (string/split (slurp "Procfile.dev") #"\n" )))
(defn has-tmux-session? (defn has-session?
"Tests to see if a session already exists with a given name." "Tests to see if a session already exists with a given name."
[session-name] [session-name]
(string/includes? (:out (shell {:out :string} "tmux list-sessions")) session-name)) (string/includes? (:out (shell {:out :string} "tmux list-sessions")) session-name))
(defn has-tmux-window? (defn has-window?
"Tests to see if a window already exists within a tmux session." "Tests to see if a window already exists within a tmux session."
[session-name window-name] [session-name window-name]
(string/includes? (:out (shell {:out :string} (format "tmux list-windows -t '%s'" session-name))) window-name)) (string/includes? (:out (shell {:out :string} (format "tmux list-windows -t '%s'" session-name))) window-name))
(defn create-tmux-window (defn create-window
"Creates a new tmux window in a session if it dose not already exists. Then "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." it will run any commands that are passed inside the new window."
[project name & commands] [project name & commands]
(when-not (has-tmux-window? project name) (when-not (has-window? project name)
(shell (format "tmux new-window -t '%s' -n '%s'" project name)) (shell (format "tmux new-window -t '%s' -n '%s'" project name))
(doseq [command commands] (doseq [command commands]
(shell (format "tmux send-keys -t %s:'%s' '%s' C-m" project name command))))) (shell (format "tmux send-keys -t %s:'%s' '%s' C-m" project name command)))))
(defn tmux-start [file] (defn command-start [_]
(when (not (has-tmux-session? (current-project-name))) (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)))
(shell (format "tmux new-session -d -c %s -s '%s'" (fs/cwd) (current-project-name)))) (shell (format "tmux new-session -d -c %s -s '%s'" (fs/cwd) (current-project-name))))
(doseq [[name command] (parse-procfile file)] (doseq [[name command] (parse-procfile)]
(create-tmux-window (current-project-name) name command))) (create-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 [_] (defn command-stop [_]
(when (has-tmux-session? (current-project-name)) (when (has-session? (current-project-name))
(shell (format "tmux kill-session -t '%s'" (current-project-name))))) (shell (format "tmux kill-session -t '%s'" (current-project-name)))))
(defn command-restart [args] (defn command-restart [args]
@ -111,7 +71,7 @@
(println "")) (println ""))
(def command-table (def command-table
[{:cmds ["start"] :fn command-start :opts {:file "Procfile.dev"}} [{:cmds ["start"] :fn command-start}
{:cmds ["stop"] :fn command-stop} {:cmds ["stop"] :fn command-stop}
{:cmds ["restart"] :fn command-restart} {:cmds ["restart"] :fn command-restart}
{:cmds [] :fn help}]) {:cmds [] :fn help}])

View file

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

View file

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

View file

@ -1,112 +0,0 @@
" 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,26 +1,5 @@
local wezterm = require "wezterm" 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 { return {
-- Use a sexy terminal font with ligatures. -- Use a sexy terminal font with ligatures.
-- You will need to install the beta version of the font to get the ligatures -- You will need to install the beta version of the font to get the ligatures
@ -30,36 +9,7 @@ return {
}, },
-- The nord theme to fit with everyting else -- 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 -- Give the font some more line height, just makes thinks look a bit nicer
line_height = 1.4, line_height = 1.4,
@ -73,7 +23,7 @@ return {
audible_bell = "Disabled", audible_bell = "Disabled",
-- Have a really clean UI when there is only one tab open -- Have a really clean UI when there is only one tab open
hide_tab_bar_if_only_one_tab = false, hide_tab_bar_if_only_one_tab = true,
-- Disabled all the padding, this makes vim look a lot nicer when all the -- Disabled all the padding, this makes vim look a lot nicer when all the
-- window bars go to the edges of the terminal -- window bars go to the edges of the terminal
@ -81,11 +31,7 @@ return {
warn_about_missing_glyphs = false, warn_about_missing_glyphs = false,
tab_bar_at_bottom = true, enable_wayland = false,
enable_wayland = true,
leader = { key = "b", mods = "CTRL" },
keys = { keys = {
-- Bind <CTRL-Backspace> to <CTRL-w> to `werase` in bash. This is to keep -- Bind <CTRL-Backspace> to <CTRL-w> to `werase` in bash. This is to keep
@ -97,36 +43,5 @@ return {
key = "Backspace", key = "Backspace",
action = wezterm.action.SendKey { mods = "CTRL", key = "w" }, 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 } },
}, },
} }