Committing changes to sessionizer before adding submodule
This commit is contained in:
parent
ab9c1afe1b
commit
b0002d47cd
5 changed files with 84 additions and 93 deletions
50
wezterm/.config/wezterm/kill-workspace.lua
Normal file
50
wezterm/.config/wezterm/kill-workspace.lua
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
local wezterm = require("wezterm")
|
||||
local util = require("util") -- Ensure you have your utility module available
|
||||
local M = {}
|
||||
|
||||
-- Define the kill_workspace function
|
||||
M.kill_workspace = function(workspace)
|
||||
print("Killing workspace:", workspace) -- Debugging output
|
||||
local success, stdout = wezterm.run_child_process({ "/opt/homebrew/bin/wezterm", "cli", "list", "--format=json" })
|
||||
|
||||
if success then
|
||||
local json = wezterm.json_parse(stdout)
|
||||
if not json then
|
||||
return
|
||||
end
|
||||
|
||||
local workspace_panes = util.filter(json, function(p)
|
||||
return p.workspace == workspace
|
||||
end)
|
||||
|
||||
for _, p in ipairs(workspace_panes) do
|
||||
wezterm.run_child_process({
|
||||
"/opt/homebrew/bin/wezterm",
|
||||
"cli",
|
||||
"kill-pane",
|
||||
"--pane-id=" .. p.pane_id,
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Function to set key bindings
|
||||
local function configure_keybindings()
|
||||
return {
|
||||
{
|
||||
key = "d",
|
||||
mods = "CTRL | SHIFT",
|
||||
action = wezterm.action_callback(function(window)
|
||||
local w = window:active_workspace()
|
||||
M.kill_workspace(w) -- Use the correct reference to M.kill_workspace
|
||||
end),
|
||||
},
|
||||
}
|
||||
end
|
||||
|
||||
-- Set the key bindings in the configuration
|
||||
wezterm.on("update-config", function(conf)
|
||||
conf.keys = configure_keybindings()
|
||||
end)
|
||||
|
||||
return M
|
||||
1
wezterm/.config/wezterm/sessionizer
Submodule
1
wezterm/.config/wezterm/sessionizer
Submodule
|
|
@ -0,0 +1 @@
|
|||
Subproject commit c4e19537694c24a0fc8979febb675bd16a66f681
|
||||
|
|
@ -1,79 +0,0 @@
|
|||
-- .config/wezterm/sessionizer.lua
|
||||
|
||||
-- Pull in the wezterm API
|
||||
local wezterm = require("wezterm")
|
||||
|
||||
local M = {}
|
||||
|
||||
-- Define utility functions
|
||||
-- @param cmd: The command to run
|
||||
-- @return: The output of the command
|
||||
local function run_command(cmd)
|
||||
local f = io.popen(cmd)
|
||||
if not f then
|
||||
return nil, "Failed to execute command: " .. cmd
|
||||
end
|
||||
local output = f:read("*a")
|
||||
f:close()
|
||||
return output
|
||||
end
|
||||
|
||||
-- Check if a directory is valid
|
||||
-- @param directory: The directory to check
|
||||
-- @return: Whether the directory is valid
|
||||
local function is_directory_valid(directory)
|
||||
local fd_output = run_command("fd --min-depth 1 --max-depth 5 --type d . " .. directory)
|
||||
return fd_output ~= ""
|
||||
end
|
||||
|
||||
-- Function to create or attach to a session
|
||||
-- @param selected_name: The name of the selected directory
|
||||
-- @param selected: The selected directory
|
||||
local function create_or_attach_session(selected_name, selected)
|
||||
local mux = wezterm.mux
|
||||
local window, pane, workspace = mux.spawn_window({
|
||||
workspace = selected_name,
|
||||
cwd = selected,
|
||||
})
|
||||
mux.set_active_workspace(selected_name)
|
||||
end
|
||||
|
||||
-- Main sessionizer function
|
||||
-- @param window: The window to run the sessionizer in
|
||||
-- @param pane: The pane to run the sessionizer in
|
||||
function M.run(window, pane)
|
||||
wezterm.log_info("Selecting a directory...")
|
||||
local selected = run_command(
|
||||
"fzf --preview 'tree -C {}' --preview-window=right:50%:wrap --height=100% --border --prompt='Select a directory: ' --bind='enter:accept,ctrl-c:abort' --query='' --no-mouse"
|
||||
)
|
||||
|
||||
if not selected then
|
||||
wezterm.log_error("No directory selected. Exiting.")
|
||||
return
|
||||
end
|
||||
|
||||
selected = selected:gsub("^%s*(.-)%s*$", "%1")
|
||||
local selected_name = selected:gsub("%.", "_")
|
||||
|
||||
if not is_directory_valid(selected) then
|
||||
wezterm.log_error("Invalid directory: " .. selected)
|
||||
return
|
||||
end
|
||||
|
||||
local sessions = wezterm.mux.get_sessions()
|
||||
local found = false
|
||||
for _, session in ipairs(sessions) do
|
||||
if session.name == selected_name then
|
||||
wezterm.mux.set_active_workspace(selected_name)
|
||||
found = true
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if not found then
|
||||
create_or_attach_session(selected_name, selected)
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
15
wezterm/.config/wezterm/util.lua
Normal file
15
wezterm/.config/wezterm/util.lua
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
local M = {}
|
||||
local wezterm = require("wezterm")
|
||||
|
||||
M.filter = function(tbl, callback)
|
||||
local filt_table = {}
|
||||
|
||||
for i, v in ipairs(tbl) do
|
||||
if callback(v, i) then
|
||||
table.insert(filt_table, v)
|
||||
end
|
||||
end
|
||||
return filt_table
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
@ -4,10 +4,10 @@ local act = wezterm.action
|
|||
|
||||
-- Pull custom modules
|
||||
local theme = require("theme-switcher")
|
||||
-- local kill_workspace = require("kill-workspace")
|
||||
local sessionizer = require("sessionizer.plugin.init")
|
||||
|
||||
local config = {}
|
||||
local keys = {}
|
||||
local key_tables = {}
|
||||
|
||||
-- This will hold the configuration.
|
||||
if wezterm.config_builder then
|
||||
|
|
@ -21,7 +21,7 @@ if wezterm.target_triple == "x86_64-pc-windows-msvc" then
|
|||
config.default_prog = { "wsl.exe", "~", "-d", "Ubuntu-20.04" }
|
||||
elseif wezterm.target_triple == "x86_64-apple-darwin" then
|
||||
config.macos_window_background_blur = 10
|
||||
config.default_prog = { "/bin/zsh", "-l" }
|
||||
config.default_prog = { "/bin/bash", "-l" }
|
||||
config.font = wezterm.font_with_fallback({
|
||||
{ family = "MesloLGS NF", scale = 0.9 },
|
||||
{ family = "Menlo", scale = 0.9 },
|
||||
|
|
@ -135,7 +135,7 @@ config.set_environment_variables = {
|
|||
|
||||
config.leader = { key = "a", mods = "CTRL", timeout_milliseconds = 1000 }
|
||||
|
||||
keys = {
|
||||
local keys = {
|
||||
{ key = "LeftArrow", mods = "OPT", action = act.SendString("\x1bb") },
|
||||
{ key = "RightArrow", mods = "OPT", action = act.SendString("\x1bf") },
|
||||
|
||||
|
|
@ -169,14 +169,6 @@ keys = {
|
|||
{ key = " ", mods = "LEADER", action = act.ActivateTabRelative(1) },
|
||||
{ key = "x", mods = "LEADER", action = act({ CloseCurrentPane = { confirm = true } }) },
|
||||
|
||||
{
|
||||
key = "f",
|
||||
mods = "LEADER",
|
||||
action = act.SpawnCommandInNewTab({
|
||||
args = { config.default_prog[1], "-c", "sessionizer" },
|
||||
}),
|
||||
},
|
||||
|
||||
{
|
||||
key = "]",
|
||||
mods = "LEADER",
|
||||
|
|
@ -263,7 +255,7 @@ keys = {
|
|||
action = act.ReloadConfiguration,
|
||||
},
|
||||
|
||||
-- Swich to default orkspace
|
||||
-- Swich to default workspace
|
||||
{
|
||||
key = "y",
|
||||
mods = "CTRL | SHIFT",
|
||||
|
|
@ -329,7 +321,8 @@ keys = {
|
|||
-- Paste from Copy Mode
|
||||
{ key = "y", mods = "LEADER", action = act.PasteFrom("PrimarySelection") },
|
||||
}
|
||||
key_tables = {
|
||||
|
||||
local key_tables = {
|
||||
copy_mode = {
|
||||
{ key = "c", mods = "CTRL", action = act.CopyMode("Close") },
|
||||
{ key = "q", mods = "NONE", action = act.CopyMode("Close") },
|
||||
|
|
@ -426,6 +419,17 @@ key_tables = {
|
|||
config.keys = keys
|
||||
config.key_tables = key_tables
|
||||
|
||||
local projects = {
|
||||
wezterm.home_dir .. "/.dotfiles",
|
||||
wezterm.home_dir .. "/Documents",
|
||||
wezterm.home_dir .. "/.local/bin",
|
||||
wezterm.home_dir .. "/Google\\ Drive/My\\ Drive",
|
||||
-- wezterm.home_dir .. "/.local/bin/fake_project", -- test project
|
||||
}
|
||||
|
||||
sessionizer.set_projects(projects)
|
||||
sessionizer.configure(config)
|
||||
|
||||
-- wezterm.on("window-config-reload", function()
|
||||
-- -- Set up the meeting notifier to check every 60 seconds
|
||||
-- -- meeting_notifier.setup_update_timer(15)
|
||||
|
|
|
|||
Loading…
Reference in a new issue