From 14b60be2a7842373d11267784fe53ced44074fae Mon Sep 17 00:00:00 2001 From: Cynthia Foxwell Date: Thu, 31 Aug 2023 22:10:15 -0600 Subject: [PATCH] clink --- .gitmodules | 3 + .../AppData/Local/clink/clink-completions | 1 + .../home/AppData/Local/clink/clink_start.cmd | 6 + windows/home/AppData/Local/clink/init.lua | 302 ++++++++++++++++++ .../home/AppData/Local/clink/setup_clink.bat | 18 ++ windows/home/AppData/Roaming/bug.n/Config.ini | 34 +- 6 files changed, 353 insertions(+), 11 deletions(-) create mode 160000 windows/home/AppData/Local/clink/clink-completions create mode 100644 windows/home/AppData/Local/clink/clink_start.cmd create mode 100644 windows/home/AppData/Local/clink/init.lua create mode 100644 windows/home/AppData/Local/clink/setup_clink.bat diff --git a/.gitmodules b/.gitmodules index bd94e8c..dd6bcd7 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,3 +7,6 @@ [submodule "linux/.config/awesome/cyclefocus"] path = linux/.config/awesome/cyclefocus url = https://github.com/blueyed/awesome-cyclefocus +[submodule "windows/home/AppData/Local/clink/clink-completions"] + path = windows/home/AppData/Local/clink/clink-completions + url = https://github.com/vladimir-kotikov/clink-completions.git diff --git a/windows/home/AppData/Local/clink/clink-completions b/windows/home/AppData/Local/clink/clink-completions new file mode 160000 index 0000000..9087cc8 --- /dev/null +++ b/windows/home/AppData/Local/clink/clink-completions @@ -0,0 +1 @@ +Subproject commit 9087cc864eb156c75284bdf99f5cea5df82add85 diff --git a/windows/home/AppData/Local/clink/clink_start.cmd b/windows/home/AppData/Local/clink/clink_start.cmd new file mode 100644 index 0000000..f34dd02 --- /dev/null +++ b/windows/home/AppData/Local/clink/clink_start.cmd @@ -0,0 +1,6 @@ +@echo off +doskey cd=cd /d $* +doskey clear=cls +doskey rm=rm -i $* +doskey cp=cp -i $* +doskey mv=mv -i $* \ No newline at end of file diff --git a/windows/home/AppData/Local/clink/init.lua b/windows/home/AppData/Local/clink/init.lua new file mode 100644 index 0000000..419b0d3 --- /dev/null +++ b/windows/home/AppData/Local/clink/init.lua @@ -0,0 +1,302 @@ +-- luacheck: globals clink +local CLINK_HOME = clink.get_env("LOCALAPPDATA") .. "/clink/" + +-- {{{ prompt +local colors = { + black = 0, + red = 1, + green = 2, + yellow = 3, + blue = 4, + magenta = 5, + cyan = 6, + white = 7, + reset = 9, +} +local function c(color, bright) + bright = bright == nil and false or bright + + return "\x1b[" .. (bright and "9" or "3") .. tostring(colors[color] or 9) .. "m" +end + +local function escape_gsub_find_arg(text) + return text and text:gsub("([-+*?.%%()%[%]$^])", "%%%1") or "" +end +local function escape_gsub_replace_arg(text) + return text and text:gsub("%%", "%%%%") or "" +end +local function gsub_plain(str, find, replace) + return string.gsub(str, escape_gsub_find_arg(find), escape_gsub_replace_arg(replace)) +end + +local function get_folder_name(path) + local reversePath = string.reverse(path) + local slashIndex = string.find(reversePath, "\\") + + if slashIndex == nil then return path end + + local folder = string.sub(path, string.len(path) - slashIndex + 2) + + if folder == "" then + return path + else + return folder + end +end + +local old_prompt = "" +local old = clink.promptfilter(0) +function old:filter(prompt) + old_prompt = prompt +end + +local lambda = clink.promptfilter(10) +function lambda:filter(prompt) + local code = tonumber(os.geterrorlevel()) + return " " .. c(code == 0 and "magenta" or "red") .. "λ" .. c("reset") .. " " +end + +local cwd_prompt = clink.promptfilter(20) +function cwd_prompt:filter(prompt) + local cwd = old_prompt:match('.*(.:[^>]*)>') + if cwd == nil then cwd = clink.get_cwd() end + + if string.find(cwd, clink.get_env("HOME")) then + cwd = gsub_plain(cwd, clink.get_env("HOME"), "~") + end + + cwd = get_folder_name(cwd) + + return prompt .. " " .. cwd .. " " +end + +local function get_git_dir(path) + + -- return parent path for specified entry (either file or directory) + local function pathname(path) -- luacheck: ignore 432 + local prefix = "" + local i = path:find("[\\/:][^\\/:]*$") + if i then + prefix = path:sub(1, i-1) + end + + return prefix + end + + -- Checks if provided directory contains git directory + local function has_git_dir(dir) + return clink.is_dir(dir..'/.git') and dir..'/.git' + end + + local function has_git_file(dir) + local gitfile = io.open(dir..'/.git') + if not gitfile then return false end + + local line = gitfile:read() or '' + local git_dir = line:match('gitdir: (.*)') + gitfile:close() + + if os.isdir then -- only available in Clink v1.0.0 and higher + if git_dir and os.isdir(git_dir) then + return git_dir + end + end + + return git_dir and dir..'/'..git_dir + end + + -- Set default path to current directory + if not path or path == '.' then path = clink.get_cwd() end + + -- Calculate parent path now otherwise we won't be + -- able to do that inside of logical operator + local parent_path = pathname(path) + + return has_git_dir(path) + or has_git_file(path) + -- Otherwise go up one level and make a recursive call + or (parent_path ~= path and get_git_dir(parent_path) or nil) +end + +local function get_git_branch(git_dir) + git_dir = git_dir or get_git_dir() + + -- If git directory not found then we're probably outside of repo + -- or something went wrong. The same is when head_file is nil + local head_file = git_dir and io.open(git_dir..'/HEAD') + if not head_file then return end + + local HEAD = head_file:read() + head_file:close() + + -- If HEAD is missing, something is wrong. + if not HEAD then return end + + -- if HEAD matches branch expression, then we're on named branch + -- otherwise it is a detached commit + local branch_name = HEAD:match('ref: refs/heads/(.+)') + + return branch_name or 'HEAD detached at '..HEAD:sub(1, 7) +end + +local io_popenyield +local clink_promptcoroutine +local cached_info = {} +if clink.promptcoroutine and io.popenyield then + io_popenyield = io.popenyield + clink_promptcoroutine = clink.promptcoroutine +else + io_popenyield = io.popen + clink_promptcoroutine = function (func) + return func(false) + end +end + +local function get_git_status() + local file = io_popenyield("git --no-optional-locks status --porcelain 2>nul") + if not file then + return {} + end + + local conflict_found = false + local is_status = true + for line in file:lines() do + local code = line:sub(1, 2) + -- print (string.format("code: %s, line: %s", code, line)) + if code == "DD" or code == "AU" or code == "UD" or code == "UA" or code == "DU" or code == "AA" or code == "UU" then -- luacheck: no max line length + is_status = false + conflict_found = true + break + -- unversioned files are ignored, comment out 'code ~= "!!"' to unignore them + elseif code ~= "!!" and code ~= "??" then + is_status = false + end + end + file:close() + + return { status = is_status, conflict = conflict_found } +end + +local function get_git_info_table() + local info = clink_promptcoroutine(function () + return get_git_status() + end) + if not info then + info = cached_info.git_info or {} + else + cached_info.git_info = info + end + return info +end + +local git_colors = { + clean = c("green"), + dirty = c("yellow"), + conflict = c("red"), + nostatus = c("white"), +} + +local git = clink.promptfilter(30) +function git:filter(prompt) + local git_dir = get_git_dir() + local color + if git_dir then + local branch = get_git_branch(git_dir) + if branch then + -- If in a different repo or branch than last time, discard cached info. + if cached_info.git_dir ~= git_dir or cached_info.git_branch ~= branch then + cached_info.git_info = nil + cached_info.git_dir = git_dir + cached_info.git_branch = branch + end + + -- If we're inside of git repo then try to detect current branch + -- Has branch => therefore it is a git folder, now figure out status + local gitInfo = get_git_info_table() + local gitStatus = gitInfo.status + local gitConflict = gitInfo.conflict + + if gitStatus == nil then + color = git_colors.nostatus + elseif gitStatus then + color = git_colors.clean + else + color = git_colors.dirty + end + + if gitConflict then + color = git_colors.conflict + end + + return prompt .. " " .. c("cyan") .. branch .. " " .. color .. "▲" .. c("reset") .. " " + end + end + + return prompt +end + +local clock = clink.promptfilter(40) +function clock:filter(prompt) end +function clock:rightfilter(prompt) + return c("white") .. " " .. os.date("%H:%M:%S") .. " " +end + +local last_run = os.clock() + +local function format_time(time) + local out = "" + + if time >= 3600 then + out = out .. math.floor(time / 3600) .. "h" + end + + if time >= 60 then + out = out .. math.floor(time % 3600 / 60) .. "m" + end + + out = out .. math.floor(time % 60) .. "s" + + return out +end + +local exectime = clink.promptfilter(50) +function exectime:filter(prompt) end +function exectime:rightfilter(prompt) + local delta = os.clock() - last_run + if delta < 3 then + return prompt + end + + return c("yellow") .. " " .. format_time(delta) .. " " .. prompt +end + +local exitcode = clink.promptfilter(60) +function exitcode:filter(prompt) end +function exitcode:rightfilter(prompt) + local code = tonumber(os.geterrorlevel()) + if code == 0 then + return prompt + else + return c("red") .. " " .. code .. " " .. prompt + end +end + +local finish = clink.promptfilter(100) +function finish:filter(prompt) + last_run = os.clock() + return prompt .. " ", false +end +-- }}} + +-- {{{ completions +local completions_dir = CLINK_HOME .. "clink-completions/" +dofile(completions_dir .. ".init.lua") +for _,lua_module in ipairs(clink.find_files(completions_dir.."*.lua")) do + -- Skip files that starts with _. This could be useful if some files should be ignored + if not string.match(lua_module, "^_.*") then + local filename = completions_dir..lua_module + -- use dofile instead of require because require caches loaded modules + dofile(filename) + end +end +-- }}} \ No newline at end of file diff --git a/windows/home/AppData/Local/clink/setup_clink.bat b/windows/home/AppData/Local/clink/setup_clink.bat new file mode 100644 index 0000000..50ae819 --- /dev/null +++ b/windows/home/AppData/Local/clink/setup_clink.bat @@ -0,0 +1,18 @@ +@echo off +clink set history.shared true + +clink set clink.logo none + +clink set color.argmatcher bright green +clink set color.cmd green +clink set color.doskey green +clink set color.executable green +clink set color.unrecognized red +clink set color.input white + +clink set color.cmdsep white +clink set color.cmdredir white + +clink set color.flag cyan +clink set color.arg white +clink set color.suggestion bright black \ No newline at end of file diff --git a/windows/home/AppData/Roaming/bug.n/Config.ini b/windows/home/AppData/Roaming/bug.n/Config.ini index 2ebf644..c953da4 100644 --- a/windows/home/AppData/Roaming/bug.n/Config.ini +++ b/windows/home/AppData/Roaming/bug.n/Config.ini @@ -5,10 +5,10 @@ Config_showBar=1 Config_horizontalBarPos=0 Config_verticalBarPos=tray -Config_barWidth=192 +Config_barWidth=144 Config_singleRowBar=1 Config_spaciousBar=1 -Config_fontName=Terminus (TTF) for Windows +Config_fontName=Terminus (TTF) Config_fontSize=9 Config_largeFontSize=12 @@ -72,7 +72,7 @@ Config_fontColor_#3=a2baa8;dedbeb;dedbeb;dedbeb;dedbeb;dedbeb;dedbeb;dedbeb;dedb Config_barTransparency=off Config_barCommands= -Config_barTaskbarBlend=0 +Config_barTaskbarBlend=1 Config_readinBat=0 Config_readinCpu=0 Config_readinDate=0 @@ -99,14 +99,14 @@ Config_combineDateAndTime=1 ;; Windows ui elements Config_bbCompatibility=0 -Config_borderWidth=1 +Config_borderWidth=-1 Config_borderPadding=-1 Config_showTaskBar=1 -Config_showBorder=0 +Config_showBorder=1 ; 0x00BBGGRR, 0 = disabled Config_selBorderColor=0 -Config_classicThemeFixes=1 -Config_classicThemeTaskbar=1 +Config_classicThemeFixes=0 +Config_classicThemeTaskbar=0 ;; Window arrangement Config_viewNames=1;2;3;4;5;6;7;8;9 @@ -119,7 +119,7 @@ Config_layoutAxis_#2=2 Config_layoutAxis_#3=2 Config_layoutGapWidth=8 Config_layoutMFactor=0.5 -Config_areaTraceTimeout=0 +Config_areaTraceTimeout=1000 Config_continuouslyTraceAreas=0 Config_dynamicTiling=1 Config_ghostWndSubString= (Not Responding) @@ -166,6 +166,7 @@ Config_rule=Chrome_WidgetWin_1;.*;;1;0;0;0;1;0; Config_rule=Chrome_WidgetWin_1;.*;Window_isPopup;1;1;0;1;1;0; Config_rule=Chrome_WidgetWin_1;Developer Tools - .*;;1;1;0;1;1;0; Config_rule=Chrome_WidgetWin_1;Picture in picture;;0;;;;;0; +Config_rule=Chrome_WidgetWin_1;Extensions;;0;;;;;0; Config_rule=NarratorHelperWindow;.*;;0; Config_rule=Windows.UI.Core.CoreWindow;Search;;0;;;;;0; Config_rule=;Wox;;0;;;;;0; @@ -214,6 +215,15 @@ Config_rule=HwndWrapper[EarTrumpet.exe.+;EarTrumpet;;0;1;;0;0;0; Config_rule=ShockwaveFlash;;;0;1;;0;0;0; Config_rule=ImlWinCls;Flashpoint Shockwave Projector;;0;1;;0;0;0; Config_rule=OpenGL;Teardown;;0;1;;0;0;0; +Config_rule=KillingFloorUnrealWWindowsViewportWindow;;;0;1;;0;0;0; +Config_rule=Respawn001;Titanfall 2;;0;1;;0;0;0; +Config_rule=WindowsForms10.Window.8.app.0.1a52015_r6_ad1;ShareX - Color picker;;0;1;;0;0;0; +Config_rule=Tiger D3D Window;Destiny 2;;0;1;;0;0;0; +Config_rule=;EarTrumpet;;0;1;;0;0;0; +Config_rule=Qt5152QWindowIcon;.*86Box.*;;0;1;;0;0;0; +Config_rule=HwndWrapper[EverythingToolbar.Launcher.exe.+;;;0;1;;0;0;0; +Config_rule=Chrome_WidgetWin_1;Discord Updater;;0;1;;0;0;0; +Config_rule=ActivateLinux;ActivateLinux;;0;1;;0;0;0; ;; Configuration management Config_autoSaveSession=auto @@ -233,8 +243,8 @@ Config_hotkey=#+s:: Config_hotkey=#+x:: Config_hotkey=#i::Manager_getWindowInfo() Config_hotkey=#+i::Manager_getWindowList() -Config_hotkey=!Down::View_moveWindow(0, +1) -Config_hotkey=!Up::View_moveWindow(0, -1) +Config_hotkey=!Down:: +Config_hotkey=!Up:: Config_hotkey=!1:: Config_hotkey=!2:: Config_hotkey=!3:: @@ -269,6 +279,8 @@ Config_hotkey=#^Right::View_setLayoutProperty(MX, 0, +1) Config_hotkey=#^Left::View_setLayoutProperty(MX, 0, -1) Config_hotkey=#+Left:: Config_hotkey=#+Right:: +Config_hotkey=#+w::View_moveWindow(0, -1) +Config_hotkey=#+s::View_moveWindow(0, +1) ;; View/Tag management Config_hotkey=#+n:: @@ -302,7 +314,7 @@ Config_hotkey=#+Space::Monitor_toggleBar() Config_hotkey=#q::Manager_closeWindow() Config_hotkey=#+d::Window_toggleDecor() Config_hotkey=#f::View_toggleFloatingWindow() -Config_hotkey=#t::View_setLayout(1) +Config_hotkey=#t::Manager_toggleManage() Config_hotkey=#m::View_setLayout(2) Config_hotkey=#+f::View_setLayout(3) Config_hotkey=!+Enter::Manager_maximizeWindow()