~piotr-machura/dotfiles

26675cdb7d27ba62a686bb0c90f8bb191fbaaf21 — Piotr Machura a month ago 3faa939
Move kakoune filetypes to a separate file
M .bashrc => .bashrc +12 -15
@@ 8,8 8,8 @@
# ALIASES
# -------
alias ls='ls --color=auto'
alias la='\ls --almost-all --color=auto'
alias ll='\ls -l --almost-all --human-readable --color=auto'
alias la='ls --almost-all'
alias ll='ls -l --almost-all --human-readable'
alias rm='rmtrash --interactive=once --forbid-root=pass'
alias rr='rmtrash --interactive=once --forbid-root=pass --recursive'
alias rmforce='\rm --recursive --force'


@@ 22,22 22,20 @@ alias rman='rustup man'
alias rgdb='rust-gdb -q -ex "layout src"'
alias tectonic='tectonic -X'
alias R="R --quiet"

alias cd="sk_cd"
alias ed="sk_edit"
alias open="sk_open"
alias man="sk_man"
alias kill="sk_kill"

alias serve='python3 -m http.server --directory'
alias pdb='python3 -m pdb'
alias pacclean='sudo pacman -Rns $(pacman -Qdtq --noconfirm); sudo paru -Sc --noconfirm'

pacclean() {
    pacman -Qdtq --noconfirm |
        sudo pacman -Rns -
    paru -Sc --noconfirm
}

menudiff() {
    systemfile=$(mktemp systemwide.XXX)
    userfile=$(mktemp user.XXX)
    ls /usr/share/applications/ > "$systemfile"
    ls "$XDG_DATA_HOME/applications/" > "$userfile"
    systemfile=$(mktemp --tmpdir system-menu.XXXX)
    userfile=$(mktemp --tmpdir user-menu.XXXX)
    ls /usr/share/applications/ >"$systemfile"
    ls "$XDG_DATA_HOME/applications/" >"$userfile"
    delta "$systemfile" "$userfile"
}



@@ 65,7 63,6 @@ _prompt_fn() {
    dirprefix=''
    [ "$(stat -c "%u" "$PWD")" != "$UID" ] && dirprefix="\[\e[1;31m\] "
    prompt="\[\e[1;37m\][$usercolor\u@\h $dirprefix\[\e[1;36m\]\w\[\e[1;37m\]] $prompt\[\e[m\]\n"
    # Dollar sign is handled by inputrc
    prompt="$prompt\[\e[32m\] \[\e[m\]"
    # Set prompt
    PS1="$(echo -e "$prompt")"

A .config/kak/filetypes.kak => .config/kak/filetypes.kak +63 -0
@@ 0,0 1,63 @@
# KAKOUNE FILETYPE OPTIONS
# ------------------------

hook global WinSetOption filetype=python %{
    add-highlighter shared/python/code/ regex \b([a-zA-Z_]\w*)\h*(?=\() 0:function
}

hook global WinSetOption filetype=sh %{
    set-option buffer formatcmd "shfmt -i %opt{indentwidth} -"
}

hook global WinSetOption filetype=markdown %{
    remove-highlighter shared/markdown/inline/text/regex_(?<!_)(_([^\s_]|([^\s_](\n?[^\n_])*[^\s_]))_)(?!_)_1:+i
}

hook global WinSetOption filetype=(c|cpp) %sh{
    echo "set-option buffer formatcmd 'indent -linux'"
    echo "set-option buffer indentwidth 0"
    echo "noexpandtab"
    regex="regex \b([a-zA-Z_]\w*)\h*(?=\()" 
    for ft in c cpp; do
        echo "add-highlighter -override shared/$ft/code/ $regex 0:function"
    done
}

hook global WinSetOption filetype=makefile %{
    noexpandtab
}

hook global WinSetOption filetype=xml %{
    set-option buffer indentwidth 2
}

hook global WinSetOption filetype=lua %{
    set-option buffer indentwidth 2
    set-option buffer formatcmd "stylua -"
}

hook global WinSetOption filetype=(html|javascript|css|scss|json|yaml) %{
    set-option buffer indentwidth 2
    set-option buffer formatcmd "prettier --parser %opt{filetype}"
}

# PROSE
# -----
define-command -hidden prose-detect %{
    evaluate-commands %sh{
        if [ -d "$(dirname $kak_buffile)/.words" ]
        then
            echo "set-option buffer filetype prose"
        fi
    }
}

hook global BufOpenFile .*\.txt prose-detect
hook global BufOpenFile .*\.txt prose-detect

hook global WinSetOption filetype=prose %{
    add-highlighter buffer/ wrap -word -marker '' -width %opt{fmtwidth}
    set-option -add buffer ui_options terminal_enable_mouse=true
    map buffer insert <minus> –
    noexpandtab
}

M .config/kak/kakrc => .config/kak/kakrc +6 -54
@@ 32,9 32,10 @@ map global normal , <space>
declare-user-mode format
map global user q %{: enter-user-mode format<ret>} -docstring 'Format mode'
map global format q %{: format<ret>} -docstring 'formatcmd (buffer)'
map global format Q %{: format-selections<ret>} -docstring 'formatcmd (selection)'
map global format l %{: lsp-formatting<ret>} -docstring 'lsp (buffer)'
map global format L %{: lsp-range-formatting<ret>} -docstring 'lsp (selection)'
map global format w %{: format-width<ret>} -docstring 'flow (selection)'
map global format w %{: format-width<ret>} -docstring 'width (selection)'

# Window mode
declare-user-mode window


@@ 43,8 44,9 @@ map global window n %{: bn<ret>} -docstring 'next'
map global window p %{: bp<ret>} -docstring 'previous'
map global window d %{: db<ret>} -docstring 'delete'
map global window b %{:b<space>} -docstring 'buffers'
map global window N %{:new<space>} -docstring 'new'
map global window o %{:new<space>} -docstring 'open'
map global window s %{: skim<ret>} -docstring 'skim'
map global window q %{: wqa<ret>} -docstring 'quit'

# Comment mode
declare-user-mode comment


@@ 114,56 116,6 @@ map global user l %{: enter-user-mode lsp<ret>} -docstring 'LSP mode'
lsp-inlay-diagnostics-disable global
lsp-inline-diagnostics-disable global

# LANGUAGES
# FILETYPES
# ---------
hook global WinSetOption filetype=python %{
    add-highlighter shared/python/code/function regex \b([a-zA-Z_]\w*)\h*(?=\() 0:function
}

hook global WinSetOption filetype=sh %{
    set-option buffer formatcmd "shfmt -i %opt{indentwidth} -"
}

hook global WinSetOption filetype=(c|cpp) %sh{
    for ft in c cpp; do
        echo "add-highlighter shared/$ft/code/function regex \b([a-zA-Z_]\w*)\h*(?=\() 0:function"
    done
    echo "set-option buffer formatcmd 'indent -linux'"
    echo "set-option buffer indentwidth 0"
    echo "noexpandtab"
}

hook global WinSetOption filetype=makefile %{
    noexpandtab
}

hook global WinSetOption filetype=xml %{
    set-option buffer indentwidth 2
}

hook global WinSetOption filetype=lua %{
    set-option buffer indentwidth 2
    set-option buffer formatcmd "stylua -"
}

hook global WinSetOption filetype=(html|javascript|css|scss|json|yaml) %{
    set-option buffer indentwidth 2
    set-option buffer formatcmd "prettier --parser %opt{filetype}"
}

# PROSE
# -----
define-command -hidden prose-detect %{
    evaluate-commands %sh{
        if [ -d "$(dirname $kak_buffile)/.words" ]
        then
            echo "set-option buffer filetype prose"
        fi
    }
}
hook global BufOpenFile .*\.txt prose-detect
hook global BufOpenFile .*\.txt prose-detect
hook global WinSetOption filetype=prose %{
    add-highlighter buffer/ wrap -word -marker '' -width %opt{fmtwidth}
    noexpandtab
}
source %sh{ echo "$XDG_CONFIG_HOME/kak/filetypes.kak" }

M .config/sk.bash => .config/sk.bash +0 -70
@@ 9,76 9,6 @@ colors="$colors,header:2,info:0,query:7,pointer:3,marker:1,prompt:3,cursor:6,spi
export SKIM_DEFAULT_OPTIONS="--ansi --reverse --no-hscroll --height 50% --prompt ' ' --cmd-prompt ' '"
export SKIM_DEFAULT_OPTIONS="$SKIM_DEFAULT_OPTIONS --color '$colors'"

# Edit
sk_edit() {
    IFS=$'\n'
    files=$(sk --query="$(echo -ne $@)" --multi --header='Edit:')
    [ -n "$files" ] && echo "$files" && "$EDITOR" ${files[@]}
}

# Open
sk_open() {
    if [ "$#" -gt 0 ]; then
        \open "$@"
        return
    fi
    IFS=$'\n'
    local files
    files="$(sk --multi --header='Open:')"
    [ -n "$files" ] && echo "$files" && \open ${files[@]}
}

# Interactive cd
sk_cd() {
    if [ "$#" -gt 0 ]; then
        builtin cd "$@"
        return
    fi
    local dirs=""
    local d="$PWD"
    while [ "$d" != '/' ]; do
        d=$(dirname "$d")
        dirs+="\n$d"
    done
    d=$(cat <(echo -e "$dirs") <(fd -H --exclude '.git' --type directory) |
        sk --header='Directories:')
    [ -n "$d" ] && echo "$d" && builtin cd "$d"
}

# Interactive kill
sk_kill() {
    if [ "$#" -gt 0 ]; then
        builtin kill "$@"
        return
    fi
    local pid
    if [ "$UID" != "0" ]; then
        pid=$(ps -f -u $UID |
            sed 1d |
            sk --header='Processes:' --multi |
            awk '{print $2}')
    else
        pid=$(ps -ef |
            sed 1d |
            sk --header='Processes:' --multi |
            awk '{print $2}')
    fi
    [ -n "$pid" ] && builtin kill -"${1:-9}" "$pid"
}

# Manpages
sk_man() {
    if [ "$#" -gt 0 ]; then
        /bin/man "$@"
        return
    fi
    /bin/man -k . |
        sk --header='Man:' |
        tr -d '()' |
        awk '{printf "%s ", $2} {print $1}' |
        xargs -r /bin/man
}

# Git commit preview
sk_commits_preview() {
    git log --graph --color=always --format="%C(auto)%h%d %s" "$@" |

A .local/share/applications/element.desktop => .local/share/applications/element.desktop +8 -0
@@ 0,0 1,8 @@
[Desktop Entry]
Type=Application
Name=Element
Comment=Shortcut to the email inbox
Exec=xdg-open "https://app.element.io/#/home"
Icon=element
Terminal=false


A .local/share/applications/l3afpad.desktop => .local/share/applications/l3afpad.desktop +9 -0
@@ 0,0 1,9 @@
[Desktop Entry]
Name=Leafpad
Comment=Simple text editor
Exec=l3afpad %f
Icon=l3afpad
Terminal=false
Type=Application
MimeType=text/plain;
Categories=GTK;Utility;TextEditor;

M .local/share/pacman/aur.txt => .local/share/pacman/aur.txt +1 -1
@@ 12,6 12,6 @@ rar
rmtrash
rstudio-desktop-bin
stylua-bin
tiny-irc-client-bin
teams
vscode-langservers-extracted
xcursor-breeze

M .profile => .profile +1 -0
@@ 8,6 8,7 @@ export PAGER='less -r'
export TERMINAL='alacritty -e'
export BROWSER='firefox'
export MANPAGER='less -r'
export TMPDIR='/tmp'

# XDG BASE DIRECTORY SPECIFICATION
# --------------------------------