From baf0ee5255225fe58e2aeed7b38de194e21959fa Mon Sep 17 00:00:00 2001 From: js0ny Date: Sun, 22 Dec 2024 09:24:18 +0000 Subject: [PATCH] feat(wezterm): add wezterm config --- .gitignore | 2 + bootstrap/Windows.ps1 | 7 +- {scripts => tools/powershell}/Completions.ps1 | 1 + tools/powershell/Config.ps1 | 15 ++- tools/powershell/Modules.ps1 | 2 +- tools/powershell/Prompt.ps1 | 2 +- tools/wezterm/wezterm.lua | 121 ++++++++++++++++++ 7 files changed, 142 insertions(+), 8 deletions(-) rename {scripts => tools/powershell}/Completions.ps1 (78%) create mode 100644 tools/wezterm/wezterm.lua diff --git a/.gitignore b/.gitignore index e5cd05f..32a3502 100644 --- a/.gitignore +++ b/.gitignore @@ -46,3 +46,5 @@ common/fzfrc platforms/win/komorebi/applications.json gitconfig + +check_update diff --git a/bootstrap/Windows.ps1 b/bootstrap/Windows.ps1 index 2c1046d..4d59e65 100644 --- a/bootstrap/Windows.ps1 +++ b/bootstrap/Windows.ps1 @@ -16,10 +16,9 @@ Invoke-RestMethod -Uri https://get.scoop.sh | Invoke-Expression # Set Environment Variables # Use %PATH_EXT% to prevent PATH from being too long [System.Environment]::SetEnvironmentVariable("Path_EXT_0", "D:\bin", "User") -[System.Environment]::SetEnvironmentVariable("Path_EXT_0", "C:\Users\citoy\AppData\Local\Cargo\bin", "User") -[System.Environment]::SetEnvironmentVariable("Path_EXT_1", "C:\Users\citoy\AppData\Local\Cargo\bin", "User") -[System.Environment]::SetEnvironmentVariable("Path_EXT_2", "C:\Users\citoy\AppData\Local\Cargo\bin", "User") -[System.Environment]::SetEnvironmentVariable("Path_EXT_2", "", "User") +[System.Environment]::SetEnvironmentVariable("Path_EXT_0", "C:\Users\jsony\AppData\Local\Cargo\bin", "User") +[System.Environment]::SetEnvironmentVariable("Path_EXT_1", "C:\Users\jsony\AppData\Local\Go\bin", "User") +[System.Environment]::SetEnvironmentVariable("Path_EXT_2", "C:\Users\jsony\AppData\Local\Cargo\bin", "User") $currentPath = [System.Environment]::GetEnvironmentVariable("Path", "User") if ($currentPath -notlike "*%PATH_EXT%*") { $currentPath += ";%PATH_EXT_0%;%PATH_EXT_1%;%PATH_EXT_2%" diff --git a/scripts/Completions.ps1 b/tools/powershell/Completions.ps1 similarity index 78% rename from scripts/Completions.ps1 rename to tools/powershell/Completions.ps1 index 2050048..5db5e55 100644 --- a/scripts/Completions.ps1 +++ b/tools/powershell/Completions.ps1 @@ -5,5 +5,6 @@ function Invoke-Completion { 'git' { Import-Module Posh-Git } 'hugo' { hugo completion powershell | Out-String | Invoke-Expression } 'pip' { pip completion --powershell | Out-String | Invoke-Expression } + 'wezterm' { wezterm shell-completion --shell power-shell | Out-String | Invoke-Expression } } } diff --git a/tools/powershell/Config.ps1 b/tools/powershell/Config.ps1 index e7cb656..4d5ed8c 100644 --- a/tools/powershell/Config.ps1 +++ b/tools/powershell/Config.ps1 @@ -1,7 +1,18 @@ # Use XDG Base Directory Specification and its similar structure for Windows # wget -${function:wget} = {wget --hsts-file $XDG_CACHE_HOME/wget-hsts $args} +if (Get-Command wget -ErrorAction SilentlyContinue) { + ${function:wget} = {wget --hsts-file $XDG_CACHE_HOME/wget-hsts $args} +} # yarn v1 -${function:yarn} = {yarn --use-yarnrc $XDG_CONFIG_HOME/yarn/config.yaml $args} +if (Get-Command yarn -ErrorAction SilentlyContinue) { + ${function:yarn} = {yarn --use-yarnrc $XDG_CONFIG_HOME/yarn/config.yaml $args} +} + +if ($Env:WEZTERM) { # Environment variable injected by wezterm/wezterm.lua + ${function:icat} = {wezterm imgcat $args} +} +elseif ($Env:KITTY) { + ${function:icat} = {kitty +kitten icat $args} +} diff --git a/tools/powershell/Modules.ps1 b/tools/powershell/Modules.ps1 index 0137d59..8236f40 100644 --- a/tools/powershell/Modules.ps1 +++ b/tools/powershell/Modules.ps1 @@ -1,4 +1,4 @@ -Import-Module -Name Terminal-Icons +# Import-Module -Name Terminal-Icons Import-Module -Name CompletionPredictor if ($IsWindows) { # Chocolatey diff --git a/tools/powershell/Prompt.ps1 b/tools/powershell/Prompt.ps1 index 9f43a8a..da645ef 100644 --- a/tools/powershell/Prompt.ps1 +++ b/tools/powershell/Prompt.ps1 @@ -4,7 +4,7 @@ # Use starship to set prompt $ENV:STARSHIP_CONFIG = Join-Path $DOTFILES "tools" "starship" "starship_pwsh.toml" -# Invoke-Expression (&starship init powershell) +Invoke-Expression (&starship init powershell) # Below is the backup of original prompt function # $promptTime = $true diff --git a/tools/wezterm/wezterm.lua b/tools/wezterm/wezterm.lua new file mode 100644 index 0000000..3c8affb --- /dev/null +++ b/tools/wezterm/wezterm.lua @@ -0,0 +1,121 @@ +-- $DOTFILES/tools\wezterm\wezterm.lua +-- Date: 2024-12-22 +-- Author: js0ny + +-- Location: +-- $XDG_CONFIG_HOME/wezterm/wezterm.lua +-- Linking: +-- ln -sf $DOTFILES/tools/wezterm/wezterm.lua $XDG_CONFIG_HOME/wezterm/wezterm.lua + +local wezterm = require 'wezterm' + +local config = {} + +local os_type = "" +if package.config:sub(1,1) == "\\" then + -- Windows + os_type = "Windows" +elseif package.config:sub(1,1) == "/" then + -- Unix-like (Linux, macOS, etc.) + if os.getenv("HOME") then + os_type = "Unix-like" + -- You can differentiate further by checking for macOS or Linux if needed + if os.getenv("XDG_SESSION_TYPE") then + -- Likely Linux + os_type = "Linux" + elseif os.execute("uname -s | grep -i darwin") == 0 then + -- macOS + os_type = "macOS" + end + end +end + +print("[DEBUG] Detected OS: " .. os_type) + + +-- Appearance +------------------ +-- Font and color scheme +config.font = wezterm.font("FiraCode Nerd Font") +config.color_scheme = "Ayu Mirage" +config.font_size = 12.0 +if os_type == "Windows" then + config.window_background_opacity = 0.7 + config.win32_system_backdrop = 'Acrylic' +end +-- Tab appearance +config.hide_tab_bar_if_only_one_tab = true +config.tab_bar_at_bottom = true + +-- Keybindings +------------------ +config.leader = { key="q", mods="CTRL" } +config.keys = { + { + key = 'q', + mods = 'LEADER', + action = wezterm.action.SendKey {key = 'q', mods = 'CTRL'}, + }, + -- Windows Management + { + key = '|', + mods = 'LEADER|SHIFT', + action = wezterm.action.SplitHorizontal{domain="CurrentPaneDomain"} + }, + { + key = '-', + mods = 'LEADER', + action = wezterm.action.SplitVertical{domain="CurrentPaneDomain"} + }, + { + key = 'h', + mods = 'LEADER', + action = wezterm.action.ActivatePaneDirection 'Left' + }, + { + key = 'n', + mods = 'LEADER', + action = wezterm.action.ActivatePaneDirection 'Down' + }, + { + key = 'e', + mods = 'LEADER', + action = wezterm.action.ActivatePaneDirection 'Up' + }, + { + key = 'i', + mods = 'LEADER', + action = wezterm.action.ActivatePaneDirection 'Right' + }, + { + key = 'H', + mods = 'LEADER', + action = wezterm.action.AdjustPaneSize { 'Left', 5 }, + }, + { + key = 'N', + mods = 'LEADER', + action = wezterm.action.AdjustPaneSize { 'Down', 5 }, + }, + { + key = 'E', + mods = 'LEADER', + action = wezterm.action.AdjustPaneSize { 'Up', 5 }, + }, + { + key = 'I', + mods = 'LEADER', + action = wezterm.action.AdjustPaneSize { 'Right', 5 }, + }, +} +-- Environment +------------------ +if os_type == "Windows" then + config.default_prog = { "pwsh.exe" } +else + config.default_prog = { "fish" } +end +config.set_environment_variables = { + WEZTERM="true", +} +return config