dots

Dotfiles for Linux
git clone https://git.ckiri.com/cmk/dots.git
Log | Files | Refs | README

commit 39a4c81dd0cbb1423c8089b4077c9c6b7396bb14
parent f00b46dc2b07b3e3d68350b1d9bc40713035f996
Author: Chris Kiriakou <chris@kiriakou.net>
Date:   Wed, 28 Oct 2026 23:34:10 +0100

Monthly update

Diffstat:
Mfontconfig/dot-config/fontconfig/conf.d/99-inconsolata.conf | 2+-
Mfontconfig/dot-config/fontconfig/fonts.conf | 2+-
Mfoot/dot-config/foot/foot.ini | 2+-
Alabwc/dot-config/labwc/autostart | 11+++++++++++
Alabwc/dot-config/labwc/environment | 3+++
Alabwc/dot-config/labwc/menu.xml | 33+++++++++++++++++++++++++++++++++
Alabwc/dot-config/labwc/rc.xml | 251+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mscripts/dot-local/bin/status.sh | 2+-
Msway/dot-config/sway/config | 12+++++-------
Mswaynag/dot-config/swaynag/config | 2+-
Mtmux/dot-config/tmux/statusline.conf | 2+-
Mvim/dot-vimrc | 20++++++++++++++++++--
Avis/dot-config/vis/ctags/init.lua | 418+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avis/dot-config/vis/filetype/init.lua | 452+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avis/dot-config/vis/themes/min/init.lua | 41+++++++++++++++++++++++++++++++++++++++++
Avis/dot-config/vis/visrc.lua | 26++++++++++++++++++++++++++
16 files changed, 1264 insertions(+), 15 deletions(-)

diff --git a/fontconfig/dot-config/fontconfig/conf.d/99-inconsolata.conf b/fontconfig/dot-config/fontconfig/conf.d/99-inconsolata.conf @@ -4,7 +4,7 @@ <alias binding="strong"> <family>monospace</family> <prefer> - <family>Inconsolata Nerd Font Mono</family> + <family>Terminus</family> </prefer> </alias> </fontconfig> diff --git a/fontconfig/dot-config/fontconfig/fonts.conf b/fontconfig/dot-config/fontconfig/fonts.conf @@ -11,6 +11,6 @@ </alias> <alias binding="strong"> <family>monospace</family> - <prefer><family>Inconsolata</family></prefer> + <prefer><family>Terminus</family></prefer> </alias> </fontconfig> diff --git a/foot/dot-config/foot/foot.ini b/foot/dot-config/foot/foot.ini @@ -1,6 +1,6 @@ term=foot app-id=foot -font=monospace:size=11 +font=monospace:size=12 pad=0x0 center-when-maximized-and-fullscreen workers=2 diff --git a/labwc/dot-config/labwc/autostart b/labwc/dot-config/labwc/autostart @@ -0,0 +1,11 @@ +foot --server >/dev/null 2>&1 & +wlr-randr --output HDMI-A-1 --scale 1.5 >/dev/null 2>&1 & +swaybg --color "#777777" >/dev/null 2>&1 & +dconf write /org/gnome/desktop/interface/color-scheme '"prefer-light"' >/dev/null 2>&1 & +gsettings set org.gnome.desktop.interface gtk-theme 'HighContrast' >/dev/null 2>&1 & +gsettings set org.gnome.desktop.interface icon-theme '' >/dev/null 2>&1 & +gammastep -l 49.0:9.2 -t 5700:3600 >/dev/null 2>&1 & +swayidle -w \ + timeout 1800 'wlr-randr --output HDMI-A-1 off' resume 'wlr-randr --output HDMI-A-1 on' \ + timeout 3600 'systemctl suspend' >/dev/null 2>&1 & +dbus-update-activation-environment --systemd WAYLAND_DISPLAY XDG_CURRENT_DESKTOP >/dev/null 2>&1 diff --git a/labwc/dot-config/labwc/environment b/labwc/dot-config/labwc/environment @@ -0,0 +1,3 @@ +XKB_DEFAULT_LAYOUT=de +TERMINAL=footclient +_JAVA_AWT_WM_NONREPARENTING=1 diff --git a/labwc/dot-config/labwc/menu.xml b/labwc/dot-config/labwc/menu.xml @@ -0,0 +1,33 @@ +<openbox_menu> + +<menu id="client-menu"> + <item label="Maximize"> + <action name="ToggleMaximize"/> + </item> + <item label="Fullscreen"> + <action name="ToggleFullscreen"/> + </item> + <item label="Decorations"> + <action name="ToggleDecorations"/> + </item> +</menu> + +<menu id="root-menu"> + <item label="Terminal"> + <action name="Execute" command="footclient" /> + </item> + <separator /> + <item label="Reconfigure"> + <action name="Reconfigure" /> + </item> + <item label="Exit"> + <action name="If"> + <prompt message="Do you really want to exit the compositor?"/> + <then> + <action name="Exit"/> + </then> + </action> + </item> +</menu> + +</openbox_menu> diff --git a/labwc/dot-config/labwc/rc.xml b/labwc/dot-config/labwc/rc.xml @@ -0,0 +1,251 @@ +<labwc_config> + + <keyboard> + + <repeatRate>45</repeatRate> + <repeatDelay>300</repeatDelay> + + <keybind key="A-p"> + <action name="Execute" command="wmenu-run"/> + </keybind> + <keybind key="A-S-Return"> + <action name="Execute" command="footclient"/> + </keybind> + <keybind key="A-S-c"> + <action name="Close"/> + </keybind> + + <keybind key="A-S-r"> + <action name="Reconfigure"/> + </keybind> + <keybind key="A-S-q"> + <action name="If"> + <prompt message="Do you really want to exit the compositor?"/> + <then> + <action name="Exit"/> + </then> + </action> + </keybind> + + <keybind key="XF86AudioLowerVolume"> + <action name="Execute" command="wpctl set-volume @DEFAULT_SINK@ 0.02-"/> + </keybind> + <keybind key="XF86AudioRaiseVolume"> + <action name="Execute" command="wpctl set-volume @DEFAULT_SINK@ 0.02+"/> + </keybind> + <keybind key="XF86AudioMute"> + <action name="Execute" command="wpctl set-mute @DEFAULT_SINK@ toggle"/> + </keybind> + + <keybind key="W-S-s"> + <action name="Execute" command="wayshot.sh"/> + </keybind> + <keybind key="A-s"> + <action name="Execute" command="websearch.sh"/> + </keybind> + <keybind key="W-S-period"> + <action name="Execute" command="emojipicker.sh"/> + </keybind> + + <keybind key="A-m"> + <action name="ToggleMagnify"/> + </keybind> + <keybind key="A-Plus"> + <action name="ZoomIn"/> + </keybind> + <keybind key="A-Minus"> + <action name="ZoomOut"/> + </keybind> + + <keybind key="A-Tab"> + <action name="NextWindow"/> + </keybind> + <keybind key="A-j"> + <action name="NextWindow"/> + </keybind> + <keybind key="A-k"> + <action name="PreviousWindow"/> + </keybind> + + <keybind key="A-l"> + <action name="GoToDesktop" to="right" wrap="yes" toggle="no"/> + </keybind> + <keybind key="A-h"> + <action name="GoToDesktop" to="left" wrap="yes" toggle="no"/> + </keybind> + <keybind key="A-1"> + <action name="GoToDesktop" to="1" wrap="yes" toggle="no"/> + </keybind> + <keybind key="A-2"> + <action name="GoToDesktop" to="2" wrap="yes" toggle="no"/> + </keybind> + <keybind key="A-3"> + <action name="GoToDesktop" to="3" wrap="yes" toggle="no"/> + </keybind> + <keybind key="A-4"> + <action name="GoToDesktop" to="4" wrap="yes" toggle="no"/> + </keybind> + + <keybind key="A-S-l"> + <action name="SendToDesktop" to="right" follow="yes" wrap="yes"/> + </keybind> + <keybind key="A-S-h"> + <action name="SendToDesktop" to="left" follow="yes" wrap="yes"/> + </keybind> + <keybind key="A-S-1"> + <action name="SendToDesktop" to="1" follow="yes" wrap="yes"/> + </keybind> + <keybind key="A-S-2"> + <action name="SendToDesktop" to="2" follow="yes" wrap="yes"/> + </keybind> + <keybind key="A-S-3"> + <action name="SendToDesktop" to="3" follow="yes" wrap="yes"/> + </keybind> + <keybind key="A-S-4"> + <action name="SendToDesktop" to="4" follow="yes" wrap="yes"/> + </keybind> + + <keybind key="A-S-o"> + <action name="ToggleAlwaysOnTop"/> + <action name="ToggleOmnipresent"/> + </keybind> + <keybind key="A-S-f"> + <action name="ToggleFullscreen"/> + </keybind> + <keybind key="A-S-m"> + <action name="ToggleMaximize"/> + </keybind> + + + </keyboard> + + <mouse> + + <context name="Frame"> + <mousebind button="A-Right" action="Press"> + <action name="Focus"/> + <action name="Raise"/> + </mousebind> + <mousebind button="A-Right" action="Drag"> + <action name="Resize"/> + </mousebind> + <mousebind button="A-Left" action="Press"> + <action name="Focus"/> + <action name="Raise"/> + </mousebind> + <mousebind button="A-Left" action="Drag"> + <action name="Move"/> + </mousebind> + <mousebind button="A-Middle" action="Press"> + <action name="ShowMenu" menu="client-menu"/> + </mousebind> + </context> + + <context name="Border"> + <mousebind button="Left" action="Press"> + <action name="Focus"/> + <action name="Raise"/> + </mousebind> + <mousebind button="Left" action="Drag"> + <action name="Resize"/> + </mousebind> + </context> + + <context name="TitleBar"> + <mousebind button="Left" action="Press"> + <action name="Focus"/> + <action name="Raise"/> + </mousebind> + <mousebind button="Left" action="Click"> + <action name="Focus"/> + <action name="Raise"/> + </mousebind> + <mousebind button="Left" action="DoubleClick"> + <action name="ToggleMaximize"/> + </mousebind> + <mousebind button="Left" action="Drag"> + <action name="Move"/> + </mousebind> + </context> + + <context name="Client"> + <mousebind button="Left" action="Press"> + <action name="Focus"/> + <action name="Raise"/> + </mousebind> + <mousebind button="Middle" action="Press"> + <action name="Focus"/> + <action name="Raise"/> + </mousebind> + <mousebind button="Right" action="Press"> + <action name="Focus"/> + <action name="Raise"/> + </mousebind> + </context> + + <context name="Root"> + <mousebind button="Right" action="Press"> + <action name="ShowMenu" menu="root-menu"/> + </mousebind> + </context> + + <context name="Close"> + <mousebind button="Left" action="Click"> + <action name="Close"/> + </mousebind> + </context> + + <context name="Maximize"> + <mousebind button="Left" action="Click"> + <action name="ToggleMaximize"/> + </mousebind> + <mousebind button="Right" action="Click"> + <action name="ToggleMaximize" direction="horizontal"/> + </mousebind> + <mousebind button="Middle" action="Click"> + <action name="ToggleMaximize" direction="vertical"/> + </mousebind> + </context> + + </mouse> + + <desktops> + <popupTime>1000</popupTime> + <initial>Workspace 1</initial> + <names> + <name>Workspace 1</name> + <name>Workspace 2</name> + <name>Workspace 3</name> + <name>Workspace 4</name> + </names> + </desktops> + + <theme> + <titlebar> + <layout>close,max:</layout> + <showTitle>yes</showTitle> + </titlebar> + <keepBorder>yes</keepBorder> + <dropShadows>yes</dropShadows> + <cornerRadius>0</cornerRadius> + </theme> + + <windowSwitcher preview="yes" outlines="yes" unshade="yes"> + <osd show="yes" style="classic" output="all" thumbnailLabelFormat="%T"/> + <fields> + <field content="desktop_entry_name" width="15%"/> + <field content="title" width="85%"/> + </fields> + </windowSwitcher> + + <windowRules> + <windowRule identifier="*"> + <action name="ToggleDecorations"/> + </windowRule> + </windowRules> + + <menu> + <showIcons>no</showIcons> + </menu> + +</labwc_config> diff --git a/scripts/dot-local/bin/status.sh b/scripts/dot-local/bin/status.sh @@ -5,7 +5,7 @@ main() { uptime="$(uptime --pretty) | " disk="Disk: $(df --human-readable / --output=pcent | sed 1d | cut --whitespace-delimited --fields=2) | " - ram="RAM: $(free --human --line | cut --whitespace-delimited --fields=4) | " + ram="RAM: $(free --human --line | cut --whitespace-delimited --fields=6) | " date="$(date +'%a, %d.%m.%Y %H:%M') " bat_name=$(ls --format=single-column /sys/class/power_supply/ | grep -E '\b[A-Z]{2,3}[0-9]\b') test -n "${bat_name}" && bat="Bat: $(~/.local/bin/batterystate.sh ${bat_name}) | " diff --git a/sway/dot-config/sway/config b/sway/dot-config/sway/config @@ -12,20 +12,18 @@ set $opm_off 'swaymsg "output * power off"' set $opm_on 'swaymsg "output * power on"' # Options ###################################################################### floating_modifier $mod -gaps inner 10 -gaps outer 10 +font Monospace 9 +titlebar_padding 2 2 # Autostart apps ############################################################### exec swayidle -w \ timeout 900 $opm_dim resume $opm_restore \ timeout 1200 'swaylock -f' \ timeout 1260 $opm_off resume $opm_on \ - timeout 1800 'systemctl suspend-then-hibernate' \ before-sleep 'swaylock -f' >/dev/null 2>&1 exec gammastep -l 49.0:9.2 -t 5700:3600 >/dev/null 2>&1 exec foot --server >/dev/null 2>&1 -exec ~/.local/bin/switch-scheme.sh --auto >/dev/null 2>&1 +exec ~/.local/bin/switch-scheme.sh --dark >/dev/null 2>&1 exec swaybg --color '#777777' >/dev/null 2>&1 -exec gromit-mpx >/dev/null 2>&1 exec dbus-update-activation-environment \ --systemd WAYLAND_DISPLAY XDG_CURRENT_DESKTOP >/dev/null 2>&1 exec_always swaymsg focus_follows_mouse no >/dev/null 2>&1 @@ -116,10 +114,10 @@ no_focus [title="Make"] # Statusbar #################################################################### bindsym $mod+Comma bar mode toggle bar { - #mode hide position bottom + font Monospace 9 height 0 - status_command while true; do ~/.local/bin/status.sh; sleep 30; done + status_command slstatus -s colors { background #222222 } diff --git a/swaynag/dot-config/swaynag/config b/swaynag/dot-config/swaynag/config @@ -1 +1 @@ -font=Sans-serif 10 +font=Monospace 10 diff --git a/tmux/dot-config/tmux/statusline.conf b/tmux/dot-config/tmux/statusline.conf @@ -23,7 +23,7 @@ set -g status-left-style NONE set -g status-right-style NONE set -g status-left "[#S] " -set -g status-right "" +set -g status-right "#{pane_current_path}" setw -g window-status-activity-style "underscore,fg=black,bg=white" setw -g window-status-separator " " diff --git a/vim/dot-vimrc b/vim/dot-vimrc @@ -47,9 +47,11 @@ autocmd FileType yaml setlocal tabstop=2 shiftwidth=2 softtabstop=2 expandtab autocmd FileType toml setlocal tabstop=2 shiftwidth=2 softtabstop=2 expandtab " open the notes file -nnoremap <leader>ww :e ~/notes.txt<CR> +nnoremap <leader>ww :e ~/notes.md<CR> " open a the current diary -nnoremap <leader>w<leader>w :e ~/docs/diary/<C-r>=strftime("%d%m%y")<CR>.txt<CR> +nnoremap <leader>w<leader>w :e ~/docs/diary/<C-r>=strftime("%d%m%y")<CR>.md<CR> +" render the opened .md document to html +nnoremap <leader>wh :call RenderMarkdown()<CR> " next buffer nnoremap <leader>b :bnext<CR> " previous buffer @@ -65,4 +67,18 @@ nnoremap <leader>tl <tselect<CR> nnoremap j gj nnoremap k gk +function! RenderMarkdown() abort + if expand('%:e') !=# 'md' + echohl WarningMsg | echo 'Not a Markdown file' | echohl None + return + endif + let l:out = expand('%:p:r') . '.html' + silent execute '!lowdown -s % -m css=/home/cmk/proj/main.css > ' . shellescape(l:out) + if v:shell_error == 0 + echom 'Rendered: ' . l:out + else + echohl ErrorMsg | echo 'Render failed' | echohl None + endif +endfunction + syntax off diff --git a/vis/dot-config/vis/ctags/init.lua b/vis/dot-config/vis/ctags/init.lua @@ -0,0 +1,418 @@ +require('vis') + +local positions = {} +local tags = { 'tags' } +local ctags = { actions = {} } + +local function abs_path(prefix, path) + if string.find(path, '^/') ~= nil then + return path, path + end + + if string.find(path, '^./') ~= nil then + path = path:sub(3) + end + + return prefix .. path, path +end + +local function is_directory(path) + local dir = io.open(path .. '/', 'r') + if dir then + dir:close() + return true + else + return false + end +end + +local function find_tags(path) + for i = #path, 1, -1 do + if path:sub(i, i) == '/' then + local prefix = path:sub(1, i) + for j = 1, #tags do + local tagfile = tags[j] + local filename + if tagfile:sub(1, 1) == '/' then + filename = tagfile + else + filename = prefix .. tagfile + end + if not is_directory(filename) then + local file = io.open(filename, 'r') + + if file ~= nil then + return file, prefix + end + end + end + end + end +end + +local function equals(key, word) + return key == word +end + +local function starts(key, prefix) + return string.sub(key, 1, string.len(prefix)) == prefix +end + +local function bsearch(file, word, is_prefix) + local matches = is_prefix and starts or equals + local buffer_size = 8096 + local format = '\n(.-)\t(.-)\t(.-);"\t' + + local from = 0 + local to = file:seek('end') + local startpos = nil + + while from <= to do + local mid = from + math.floor((to - from) / 2) + file:seek('set', mid) + + local content = file:read(buffer_size, '*line') + if content ~= nil then + local key, _, _ = string.match(content, format) + if key == nil then + break + end + + if matches(key, word) then + startpos = mid + end + + if key >= word then + to = mid - 1 + else + from = mid + 1 + end + else + to = mid - 1 + end + end + + if startpos ~= nil then + file:seek('set', startpos) + + local result = {} + while true do + local content = file:read(buffer_size, '*line') + if content == nil then + break + end + + for key, filename, excmd in string.gmatch(content, format) do + if matches(key, word) then + result[#result + 1] = { name = filename, excmd = excmd, tag = key } + else + return result + end + end + end + + return result + end +end + +local function get_query() + local line = vis.win.selection.line + local pos = vis.win.selection.col + local str = vis.win.file.lines[line] + + local from, to = 0, 0 + while pos > to do + from, to = str:find('[%a_]+[%a%d_]*', to + 1) + if from == nil or from > pos then + return nil + end + end + + return string.sub(str, from, to) +end + +local function get_matches(word, path, is_prefix) + local file, prefix = find_tags(path) + + if file ~= nil then + local results = bsearch(file, word, is_prefix) + file:close() + + if results ~= nil then + local matches = {} + for i = 1, #results do + local result = results[i] + local abspath, name = abs_path(prefix, result.name) + local desc = string.format('%s%s', name, tonumber(result.excmd) and ':' .. result.excmd or '') + + matches[#matches + 1] = { desc = desc, path = abspath, excmd = result.excmd, tag = result.tag } + end + + return matches + end + end +end + +local function get_match(word, path) + local matches = get_matches(word, path) + if matches ~= nil then + for i = 1, #matches do + if matches[i].path == path then + return matches[i] + end + end + + return matches[1] + end +end + +local function escape(text) + return text:gsub('[][)(}{|+?*.]', '\\%0') + :gsub('%^', '\\^') + :gsub('^/\\%^', '/^') + :gsub('%$', '\\$') + :gsub('\\%$/$', '$/') + :gsub('\\\\%$%$/$', '\\$$') +end + +--[[ +- Can't test vis:command() as it will still return true if the edit command fails. +- Can't test File.modified as the edit command can succeed if the current file is + modified but open in another window and this behavior is useful. +- Instead just check the path again after trying the edit command. +]] +local function goto_pos(pos, force) + if pos.path ~= vis.win.file.path then + vis:command(string.format(force and 'e! "%s"' or 'e "%s"', pos.path)) + if pos.path ~= vis.win.file.path then + return false + end + end + if tonumber(pos.excmd) then + vis.win.selection:to(pos.excmd, pos.col) + else + vis.win.selection:to(1, 1) + vis:command(escape(pos.excmd)) + vis.win.selection.pos = vis.win.selection.range.start + vis.mode = vis.modes.NORMAL + end + return true +end + +local function goto_tag(path, excmd, force) + local old = { + path = vis.win.file.path, + excmd = vis.win.selection.line, + col = vis.win.selection.col, + } + + local last_search = vis.registers['/'] + if goto_pos({ path = path, excmd = excmd, col = 1 }, force) then + positions[#positions + 1] = old + vis.registers['/'] = last_search + end +end + +local function pop_pos(force) + if #positions < 1 then + return + end + if goto_pos(positions[#positions], force) then + table.remove(positions, #positions) + end +end + +local function win_path() + if vis.win.file.path == nil then + return os.getenv('PWD') .. '/' + end + return vis.win.file.path +end + +local function tag_cmd(tag, force) + local match = get_match(tag, win_path()) + if match == nil then + vis:info(string.format('Tag not found: %s', tag)) + else + goto_tag(match.path, match.excmd, force) + end +end + +local function gen_vis_menu(matches) + local width = 0 + for _, match in ipairs(matches) do + width = math.max(width, match.desc:len()) + end + -- limit max width of desc field (filename) in menu + width = math.min(width, 40) + local fmt = '%' .. #tostring(#matches) .. 'd %-' .. width .. 's %s' + + local lines = {} + for i, match in ipairs(matches) do + local desc = match.desc + if desc:len() > width then + desc = '...' .. desc:sub(desc:len() - width + 4) + end + + -- work around bug displaying tabs in vis-menu and + -- provide a clearer context + local excmd = match.excmd:gsub('%s+', ' ') + excmd = excmd:gsub('^/^', '') + excmd = excmd:gsub('$/$', '') + table.insert(lines, fmt:format(i, desc, excmd)) + end + + -- limit vis-menu height to ~1/4 the window height + -- +1 gives an empty line at bottom to signify + -- that there are no more lines to scroll through + local nlines = math.min(math.floor(vis.win.height / 4), #lines) + if nlines == #lines then + nlines = nlines + 1 + end + return 'vis-menu -l ' .. nlines .. " -p 'Choose tag:' << 'EOF'\n" .. table.concat(lines, '\n') .. '\n' .. 'EOF' +end + +local function tselect_cmd(tag, force) + local matches = get_matches(tag, win_path()) + if matches == nil then + vis:info(string.format('Tag not found: %s', tag)) + else + local status, output = vis:pipe(vis.win.file, { start = 0, finish = 0 }, gen_vis_menu(matches)) + + if status ~= 0 then + vis:info('Command failed') + return + end + + local choice = tonumber(string.match(output, '%d+')) + if choice == nil or choice < 1 or choice > #matches then + vis:info('Invalid choice') + return + end + goto_tag(matches[choice].path, matches[choice].excmd, force) + end +end + +-- Code partially copied from complete-word.lua from vis; under ISC license +local function complete() + local win = vis.win + local file = win.file + local pos = win.selection.pos + if not pos then + return + end + + local range = file:text_object_word(pos > 0 and pos - 1 or pos) + if not range then + return + end + if range.finish > pos then + range.finish = pos + end + if range.start == range.finish then + return + end + local prefix = file:content(range) + if not prefix then + return + end + + vis:feedkeys('<vis-selections-save><Escape><Escape>') + -- collect words starting with prefix + vis:command('x/\\b' .. prefix .. '\\w+/') + local candidates = {} + for sel in win:selections_iterator() do + table.insert(candidates, file:content(sel.range)) + end + vis:feedkeys('<Escape><Escape><vis-selections-restore>') + local matches = get_matches(prefix, win_path(), true) + if matches then + for idx, match in pairs(matches) do + table.insert(candidates, match.tag) + end + end + if #candidates == 1 and candidates[1] == '\n' then + return + end + candidates = table.concat(candidates, '\n') + + local status, out, err = vis:pipe(candidates, 'sort -u | vis-menu -b') + if status ~= 0 or not out then + if err then + vis:info(err) + end + return + end + out = out:sub(#prefix + 1, #out - 1) + file:insert(pos, out) + win.selection.pos = pos + #out + -- restore mode to what it was on entry + vis.mode = vis.modes.INSERT +end + +vis:command_register('tag', function(argv, force, win, selection, range) + if #argv == 1 then + tag_cmd(argv[1], force) + end +end) + +vis:command_register('tselect', function(argv, force, win, selection, range) + if #argv == 1 then + tselect_cmd(argv[1], force) + end +end) + +vis:command_register('pop', function(argv, force, win, selection, range) + pop_pos(force) +end) + +vis:command_register('complete', function(argv, force, win, selection, range) + complete() +end) + +vis:option_register('tags', 'string', function(value) + tags = {} + for str in value:gmatch('([^%s]+)') do + table.insert(tags, str) + end +end, 'Paths to search for tags (separated by spaces)') + +ctags.actions.tag = function(keys) + local query = get_query() + local force = false + if query ~= nil then + tag_cmd(query, force) + end + return 0 +end + +ctags.actions.tselect = function(keys) + local query = get_query() + local force = false + if query ~= nil then + tselect_cmd(query, force) + end + return 0 +end + +ctags.actions.pop = function(keys) + pop_pos() + return 0 +end + +ctags.actions.complete = function(keys) + complete() +end + +--vis:map(vis.modes.NORMAL, '<C-]>', ctags.actions.tag) +vis:map(vis.modes.NORMAL, 'gt', ctags.actions.tag) + +--vis:map(vis.modes.NORMAL, 'g<C-]>', ctags.actions.tselect) +vis:map(vis.modes.NORMAL, 'ts', ctags.actions.tselect) + +--vis:map(vis.modes.NORMAL, '<C-t>', ctags.actions.pop) +vis:map(vis.modes.NORMAL, 'gT', ctags.actions.pop) + +vis:map(vis.modes.INSERT, '<C-n>', ctags.actions.complete) + +return ctags diff --git a/vis/dot-config/vis/filetype/init.lua b/vis/dot-config/vis/filetype/init.lua @@ -0,0 +1,452 @@ + +local M = {} +vis.ftdetect = M + +--[[ + filetype.lua identifies the opened file's filetype and sets syntax highlighting and etc + + If you want to perform per filetype settings, require this file and + vis.ftdetect[filetype][setting] + filetype usually is a lexer or a syntax see the filetype table for options + + Usually all tables here (apart from the filetypes table) values point to a lexer or + filetype[syntax] + + Example: + + vis.ftdetect.extensions.sh = "bash" + vis.ftdetect.filenames.makefile = "makefile" + vis.ftdetect.mimes["plain"] = "text" + vis.ftdetect.utilities.python3 = "python" -- for shebang + vis.ftdetect.data_patterns["^#!%s*.-[/ ]awk"] = "awk" + + If you do not want an exact match, you can use the filetypes table below + See FINDERS + table.insert(vis.ftdetect.cmake.name, "%.cmake%.in") + + Actions can be performed via the filetype table as well, assuming extensions is sh then + table.insert( vis.ftdetect.filetypes.bash.cmd, "set shell /bin/bash") + would set the shell to /bin/bash when the filetype is bash, see ACTIONS +--]] + +-- Removes all suffixes to get the real extension/filename +M.ignoresuffixes = { + -- list is luapatterns matching filename -- + "~+$", + + -- dict is extensions -- + -- Used by gsub, MUST BE "" + orig = "", bak = "", old = "", new = "" +} + +-- Dictionary of filetypes, Should match opened filename on WIN_OPEN +-- Slow and error prone due to its iterative nature, use the hashtables +-- You can still use it for per filetype settings via filetypes[syntax][cmd|lexer|actions] +-- scintilluas lexer.lua also has a detect function which is also used +local filetypes = { -- dict -- +--[[ + [filetype: string]: dict = { + filetype should be lexer, if not, set .lexer as subkey + + ACTIONS: These run if a finder succeeds + lexer: string -- Should be in lexers/$alt_name + alt_name: string -- same as lexer, BACKWARDS COMPAT + cmd: ipairs = { "command" } -- run list of commands (via vis:command(command)) + actions: ipairs = { function(win, filetype) } + + FINDERS/Searchers: + name: ipairs = { "luapattern" } -- patterns matching filename + USE M.filenames if absolute match + ext: ipairs = { "luapattern" } -- same as name (BACKWARDS COMPAT) + USE M.extensions if absolute match + utility: ipairs = { "luapattern" } for hashbang utility (no path) + USE M.utilities if absolute_match + hashbang: ipairs = { "luapattern" } Contains path+args (no #!%s+) + USE M.data_patterns or M.utilities + mime: ipairs = { "exact match" } -- NOTE: This will be removed + USE M.mimes + detect: function (file, data) + } +--]] + cmake = { + name = { "%.cmake.in$", "%.ctest.in$" } + }, + crontab = { + cmd = { "set savemethod inplace" }, + name = { "^crontab.*$" } + }, + ["git-commit"] = { + lexer = "diff", + cmd = { "set colorcolumn 72" }, + }, + lua = { + utility = { "^lua%-?5?%d?$", "^lua%-?5%.%d$" } + }, + python = { + utility = { "^python%d?" } + }, + r = { + name = { "%.Rout%.fail$", "%.Rout%.save$" } + } +} +M.filetypes = filetypes + +-- backwards compatibility + for syntax,T in pairs(filetypes) do + T.ext = {} + T.name = {} + T.mime = {} + T.utility = {} + T.hashbang = {} + T.cmd = {} + T.actions = {} + end + + -- In order to be semi backwards compatible, we create a table on each index access + -- This should be removed... eventually. + setmetatable(filetypes, { + __index = function (t,k) + local T = { + ext = {}, + name = {}, + utility = {}, + mime = {}, + hashbang = {}, + cmd = {}, + actions = {} + } + rawset(t,k,T) + return T + end + }) + +-- From here on, values MUST MATCH THE FILETYPE TABLE ABOVE +-- This is because the filetype table contains settings +-- If the lexer name changed, the filetype table will point to the correct lexer! +local L = require"lexers.lexer" + +-- This table matches filenames AND extensions +-- This is done because L.detect also mixes it +-- Single extensions only (no dots "."!) +-- filename is lowered, if its lowercase, it will match +local fnames = { + -- extensions + fs = "fsharp", + -- fs = "forth", -- DUPLICATE + ["1p"] = "man", + ["2p"] = "man", + ["3p"] = "man", + ["4p"] = "man", + ["5p"] = "man", + ["6p"] = "man", + ["7p"] = "man", + ["8p"] = "man", + ["9p"] = "man", + adoc = "asciidoc", + ash = "bash", + cjs = "javascript", + conf = "ini", + container = "systemd", + def = "modula2", + ebuild = "bash", + eml = "mail", + es = "rc", + fth = "forth", + glif = "xml", + glsl = "glsl", + h = "c", + i = "c", + i3 = "modula3", + ig = "modula3", + ily = "lilypond", + jsx = "javascript", + m3 = "modula3", + me = "man", + meson = "meson", + mg = "modula3", + mjs = "javascript", + mk = "makefile", + mod = "modula2", + mom = "man", + ms = "man", + plist = "xml", + pro = "prolog", + psm1 = "powershell", + pyi = "python", + pyx = "python", + rc = "rc", + rej = "diff", + rkt = "scheme", + sld = "scheme", + sls = "scheme", + ss = "scheme", + sv = "verilog", + tmac = "man", + tsx = "typescript", + txt = "text", + typ = "typst", + typst = "typst", + usfm = "usfm", + wiki = "mediawiki", + xhtm = "html", + yash = "bash", + + -- filenames + [".bash_logout"] = "bash", + [".bash_profile"] = "bash", + [".bashrc"] = "bash", + [".login"] = "bash", + [".mkshrc"] = "bash", + [".profile"] = "bash", + [".sh.profile"] = "bash", + [".shinit"] = "bash", + [".xprofile"] = "bash", + [".yash_profile"] = "bash", + [".yashrc"] = "bash", + APKBUILD = "bash", + COMMIT_EDITMSG = "git-commit", + Jenkinsfile = "groovy", + Vagrantfile = "ruby", + ["bash.bash.logout"] = "bash", + ["bash.bashrc"] = "bash", + ["git%-rebase%-todo"] = "git-rebase", + group = "dsv", + gshadow = "dsv", + ["meson.options"] = "meson", + ["meson_options.txt"] = "meson", + mkshrc = "bash", + passwd = "dsv", + profile = "bash", + shadow = "dsv" +} +L.detect_extensions = fnames +M.filenames = fnames +M.extensions = fnames + +-- Lookup table for mime [mime] = "lexer" +-- "text/" is prepended, you can omit it +local mimes = { + gemini = "gemini", + xml = "xml", + ["application/x-shellscript"] = "bash", + ["x-c"] = "c", + ["x-c++"] = "cpp", + ["x-coffee"] = "coffeescript", + ["x-css"] = "css", + ["x-haskell"] = "haskell", + ["x-html"] = "html", + ["x-json"] = "json", + ["x-lisp"] = "lisp", + ["x-lua"] = "lua", + ["x-makefile"] = "makefile", + ["x-markdown"] = "markdown", + ["x-moon"] = "moonscript", + ["x-objc"] = "objective_c", + ["x-perl"] = "perl", + ["x-python"] = "python", + ["x-ruby"] = "ruby", + ["x-rust"] = "rust", + ["x-sass"] = "sass", + ["x-scala"] = "scala", + ["x-script.python"] = "python", + ["x-scss"] = "sass", + ["x-shellscript"] = "bash", + ["x-tex"] = "latex", + ["x-yaml"] = "yaml", +} +M.mimes = mimes + +local utilities = { + awk = 'awk', mawk = 'awk', nawk = 'awk', gawk = 'awk', goawk = 'awk', + + sh = 'bash', ash = 'bash', dash = 'bash', + bash = 'bash', + ksh = 'bash', mksh = 'bash', + csh = 'bash', tcsh = 'bash', + zsh = 'bash', + + make = 'make', + + python = 'python', python2 = 'python', python3 = 'python', + + rc = 'rc', es = 'rc', + + tclsh = 'tcl', jimsh = 'tcl', + + lua = 'lua', + + octave = 'matlab', + perl = 'perl', + php = 'php', + ruby = 'ruby', +} +M.utilities = utilities + +M.data_patterns = { + ["^execve%("] = 'strace', + ["^#.* by RouterOS"] = 'routeros' +} +L.detect_patterns = M.data_patterns + +-- string.find(table, pattern) +local function TStringFind(tbl, subject) + for _, pattern in ipairs(tbl or {}) do + if subject:find(pattern) then + return true + end + end + return false +end + +--[[ Hashbang Utility Extractor + #! is UTILITY <SPACE> ARG + If UTILITY matches /env, its in ARG + + FreeBSD/GNU has -S flag which splits ARG by spaces and has other options + if -S is found, all options are discarded until it finds utility + options are identified as /^-|=/ + NOTE: This means a utility cannot match this pattern +--]] +local function GetHashBang(data) + local hb, pathname, args = data:match"^#![ \t]*((/%S+)[\t ]*([^\n]*))\n" + local utility = pathname and pathname:match"[^/]+$" + if utility=="env" then + local a = args:match"^%-[^S-]*S%s*(.+)" -- #!env -Ssh or -S sh + if a then + args = a + :gsub("%-[Cu] %S+", "") + :gsub("[^%s=]+=[^%s=]+","") + end + utility = args:match"%S+" + end + return hb, utility +end + + +-- Returns syntax/filetype +-- utility -> datap -> filename -> extension -> L.detect() -> mime +-- mime is supposed to be the most correct, but it execs file +-- Which is slow and semi non-portable, so its left for last +local function Detect(win) + local R + local file = win.file + + -- pass first few bytes of file to custom file type detector functions + local data = file:content(0, 256) + + local line + if data and #data > 0 then + line = file.lines[1] + local fullhb, utility = GetHashBang(data) + if fullhb then + if utility then + R = utilities[utility] + -- for utilities like python3.n, just match python3 + or utilities[utility:match"^%w+"] + if R then return R end + end + for lang, ft in pairs(M.filetypes) do + if + utility and TStringFind(ft.utility, utility) + or TStringFind(ft.hashbang, fullhb) + -- Same as below but saves us a loop + or (ft.detect and ft.detect(file, data)) + then + return lang + end + end + else + for lang, ft in pairs(M.filetypes) do + if + type(ft.detect) == 'function' and ft.detect(file, data) + then + return lang + end + end + end + end + + local path = file.name -- filepath + local name + if path and path~="" then + name = path and path:match("[^/]+$") -- filename + end + + if name then + local unchanged + local suffixes = M.ignoresuffixes + while #name > 0 and name ~= unchanged do + unchanged = name + name = name:gsub('%.([^.]+)$', suffixes) -- extensions + for _, pattern in ipairs(suffixes) do + name = name:gsub(pattern, "") + end + end + end + + if name or line then + R = L.detect(name, line or "") + or name and L.detect(name:lower(), "") + if R then return R end + end + + if name and #name > 0 then + -- detect filetype by filename pattern + for lang, ft in pairs(M.filetypes) do + for _, pattern in ipairs(ft.name or {}) do + if name:find(pattern) then return lang end + end + for _, pattern in ipairs(ft.ext or {}) do + if name:find(pattern) then return lang end + end + end + + -- run file(1) to determine mime type + local fileh = io.popen( + string.format( + "file -bL --mime-type -- '%s'", path:gsub("'", "'\\''") + ) + ) + if fileh then + local mime = fileh:read('*l') + fileh:close() + if mime then + local lexer = mimes[mime] or mimes["text/" .. mime] + if lexer then return lexer end + end + end + end + + return 'text' +end + +vis.events.subscribe(vis.events.WIN_OPEN, function(win) + local syntax = Detect(win) -- syntax/lexer/filetype + local filetype = rawget(filetypes, syntax) -- avoid backwards compatibility mt + if filetype then + for _, Action in ipairs(filetype.actions or {}) do + Action(win, filetype) + end + for _, cmd in ipairs(filetype.cmd or {}) do + vis:command(cmd) + end + syntax = filetype.lexer + or filetype.alt_name -- backwards compat + or syntax + end + -- Detect returns filetype, lexer is optional + if package.searchpath("lexers." .. syntax, package.path) then + win:set_syntax(syntax) + return + else + vis:info( + string.format( + "Lexer '%s' not found", syntax + ) + ) + end + + win:set_syntax(nil) + return +end) + diff --git a/vis/dot-config/vis/themes/min/init.lua b/vis/dot-config/vis/themes/min/init.lua @@ -0,0 +1,41 @@ +-- A minimal editor color scheme +local lexers = vis.lexers + +lexers.STYLE_DEFAULT = 'back:#ffffff,fore:black' +lexers.STYLE_NOTHING = 'back:white' +lexers.STYLE_ATTRIBUTE = 'fore:black' +lexers.STYLE_CLASS = 'fore:black' +lexers.STYLE_COMMENT = 'fore:#666666' +lexers.STYLE_CONSTANT = 'fore:black' +lexers.STYLE_DEFINITION = 'fore:black' +lexers.STYLE_ERROR = 'fore:white,back:red' +lexers.STYLE_DELETION = 'fore:black' +lexers.STYLE_FUNCTION = 'fore:black' +lexers.STYLE_KEYWORD = 'fore:black' +lexers.STYLE_LABEL = 'fore:black' +lexers.STYLE_NUMBER = 'fore:black' +lexers.STYLE_OPERATOR = 'fore:black' +lexers.STYLE_REGEX = 'fore:black' +lexers.STYLE_STRING = 'fore:blue' +lexers.STYLE_PREPROCESSOR = 'fore:black' +lexers.STYLE_TAG = 'fore:black' +lexers.STYLE_TAG_OVERDUE = 'fore:black' +lexers.STYLE_DELETION = 'fore:black' +lexers.STYLE_TYPE = 'fore:black' +lexers.STYLE_VARIABLE = 'fore:black' +lexers.STYLE_WHITESPACE = '' +lexers.STYLE_EMBEDDED = 'fore:black' +lexers.STYLE_IDENTIFIER = 'fore:black' + +lexers.STYLE_LINENUMBER = 'back:#cccccc,fore:black' +lexers.STYLE_LINENUMBER_CURSOR = lexers.STYLE_LINENUMBER +lexers.STYLE_CURSOR = 'back:white,fore:black' +lexers.STYLE_CURSOR_PRIMARY = 'back:#222222,fore:#ffffff' +lexers.STYLE_CURSOR_LINE = 'underlined' +lexers.STYLE_COLOR_COLUMN = 'back:#f2f2f2' +lexers.STYLE_SELECTION = 'back:#dddddd' +lexers.STYLE_STATUS = 'back:black,fore:#ffffff' +lexers.STYLE_STATUS_FOCUSED = 'back:black,fore:#ffffff,bold' +lexers.STYLE_SEPARATOR = lexers.STYLE_DEFAULT +lexers.STYLE_INFO = 'fore:default,back:default,bold' +lexers.STYLE_EOF = '' diff --git a/vis/dot-config/vis/visrc.lua b/vis/dot-config/vis/visrc.lua @@ -0,0 +1,26 @@ +require('vis') +require('ctags') + +vis.events.subscribe(vis.events.INIT, function() +end) + +vis.events.subscribe(vis.events.WIN_OPEN, function(win) + --vis:command('set statusbar off') + --vis:command('set number') + local ext = '' + + if win.file.name then + ext = win.file.name:match('%.([^%.]+)$') or '' + --vis:info('Extension: ' .. ext) + end + + vis:command('set expandtab on') + vis:command('set tabwidth 4') + + if ext == 'go' then + vis:command('set expandtab off') + vis:command('set tabwidth 8') + end + + vis:command('set theme min') +end)