Compare commits

...

9 commits

12 changed files with 159 additions and 94 deletions

View file

@ -32,7 +32,7 @@ function archive() {
_iterate_targets process ${targets[@]}
}
# Archive using multiple threads. Uses 50% of free RAM.
# Archive using multiple threads. Uses 75% of free RAM.
# All directories by default.
# Supports .archiveignore exclude file.
# Usage: archive_mt [DIRS]
@ -54,7 +54,7 @@ function archive_mt() {
# Determine memory limit.
local mem_free=$(_mem_free)
local mem_limit=$((mem_free/2))
local mem_limit=$((mem_free*3/4))
# create archive.
local hash=$(tar ${exclude} -c ${target} | pv -s $(/usr/bin/du -sb ${target} | awk '{print $1}') | xz -9e --threads=0 --memlimit=${mem_limit}MiB | tee ${name}.txz | sha1sum | cut -d\ -f1)

View file

@ -1,26 +1,36 @@
# CD (back) to directory.
# Finds first directory that matches the input (case-insensitive).
# CD (back to) directory.
# Goes to the exact-match dir first. If no exact match found, it finds first directory that contains the input (case-insensitive).
# Usage: cdd <DIR>
function cdd() {
local target="${1}"
local array
if [[ "${target}" = "" ]]; then
help cdd
return 2
fi
local array=($(_cdd_directories))
local result
IFS='/' read -r -a array <<< "${PWD}"
array=("${array[@]:1}")
# Make search case-insensitive.
shopt -s nocasematch
# Check for exact match ELSE look for containing.
if _contains ${target} ${array[@]}; then
local current="${PWD%/*}"
result="${current%\/$target\/*}/${target}"
else
# Make search case-insensitive.
shopt -s nocasematch
# Find desired dir.
local found=1
for (( idx=${#array[@]}-2 ; idx>=0 ; idx-- )); do
dir="${array[idx]}"
[[ "${dir}" =~ "${target}" ]] && found=0
[[ ${found} = 0 ]] && result="/${dir}${result}"
done
# Find dir name that contains input.
local found=1
for (( idx=${#array[@]}-1 ; idx>=0 ; idx-- )); do
dir="${array[idx]}"
[[ "${dir}" =~ "${target}" ]] && found=0
[[ ${found} = 0 ]] && result="/${dir}${result}"
done
# Clean-up???
shopt -u nocasematch
# Clean-up???
shopt -u nocasematch
fi
# Go there!
if [[ "${result}" != "" ]]; then
@ -31,12 +41,19 @@ function cdd() {
fi
}
_cdd_directories() {
# Get list of all parent dirs.
function _cdd_directories() {
local array
IFS='/' read -r -a array <<< "${PWD}"
array=("${array[@]:1}")
unset array[-1]
_autocomplete_first "${array[@]}"
printf "%s\n" "${array[@]}"
}
complete -o nosort -o filenames -F _cdd_directories cdd
function _comp_cdd() {
local IFS=$'\n'
local dirs=($(_cdd_directories))
_autocomplete_first ${dirs[@]}
}
complete -o nosort -o filenames -F _comp_cdd cdd

View file

@ -0,0 +1,15 @@
# Render markdown in browser using Gitea API. Because I want consistency with Gitea web render.
# Works only inside LAN.
# Usage: markdown_render <FILE.md>
function markdown_render() {
local IFS=$'\n'
local file="${1}"
local render="markdown_render.html"
if [[ "${file}" = "" ]]; then
help markdown_render
return 2
fi
curl -X POST https://git.voronind.com/markdown -d "$(cat ${file})" > "${render}" && o "${render}" && sleep 2 && rm "${render}"
}

View file

@ -124,7 +124,7 @@ function parse_titlecase() {
continue
fi
if [[ "${minors[@]}" =~ $(echo ${part} | sed -e "s/[${_PARSE_SPLIT_CHARS}]//g") ]]; then
if _contains $(echo ${part} | sed -e "s/[${_PARSE_SPLIT_CHARS}]//g") ${minors[@]}; then
echo -n "${part}"
else
echo -n "${part^}"

View file

@ -28,7 +28,7 @@ function tl() {
tmux list-sessions
}
# Rename current session. Uses current dir name by default.
# Assign name to session. Uses current dir name by default.
# Usage: tns [NAME]
function tns() {
local name="${1}"
@ -39,8 +39,8 @@ function tns() {
}
# Assign name to window. Uses current dir name by default.
# Usage: tn [NAME]
function tn() {
# Usage: tnw [NAME]
function tnw() {
local name="${1}"
[[ "${name}" = "" ]] && name="${PWD##*/}"

View file

@ -97,3 +97,22 @@ function _debug() {
function _info() {
>&2 echo -e "${color_bwhite}${*}${color_default}"
}
# Check if array contains an element (strict).
# Usage: _contains <ELEMENT> <ARRAY>
function _contains() {
local IFS=$'\n'
local target="${1}"
local array="${@:2}"
if [[ "${target}" = "" ]] || [[ "${array}" = "" ]]; then
help _contains
return 2
fi
for item in ${array[@]}; do
[[ "${item}" = "${target}" ]] && return 0
done
return 1
}

View file

@ -140,7 +140,7 @@ unmaximize=@as []
action-middle-click-titlebar='minimize'
action-right-click-titlebar='menu'
button-layout='appmenu:close'
focus-mode='sloppy'
focus-mode='click'
titlebar-font='SF Pro Display 11'
[org/gnome/desktop/session]

View file

@ -1,15 +1,21 @@
require('key/Rekey')
rekey_normal('<Leader>.', '@:') -- repeat command.
rekey_visual('<Leader>.', '@:') -- repeat command.
rekey_normal('zz', '<cmd>wa<cr>') -- save all files.
rekey_normal('<Leader>z', '<cmd>wqa<cr>') -- save & quit all.
rekey_normal('<Leader>v', 'v') -- visual select (duplicate).
rekey_normal('gh', '0') -- go left.
rekey_normal('gl', '$') -- go right.
rekey_normal('gj', 'G') -- go bottom.
rekey_normal('gk', 'gg') -- go top.
rekey_normal('U', '<C-r>') -- redo.
-- Write all we can and exit. Created this to drop non-writable stuff when piping to nvim.
function bye()
pcall(vim.cmd, "wa")
vim.cmd[[qa!]]
end
rekey_normal('<Leader>.', '@:') -- repeat command.
rekey_visual('<Leader>.', '@:') -- repeat command.
rekey_normal('zz', '<cmd>wa<cr>') -- save all files.
rekey_normal('<Leader>z', '<cmd>lua bye()<cr>') -- save & quit all.
rekey_normal('<Leader>v', 'v') -- visual select (duplicate).
rekey_normal('gh', '0') -- go left.
rekey_normal('gl', '$') -- go right.
rekey_normal('gj', 'G') -- go bottom.
rekey_normal('gk', 'gg') -- go top.
rekey_normal('U', '<C-r>') -- redo.
rekey_normal(';', ':') -- remap ; to :.
rekey_visual(';', ':') -- remap ; to :.

View file

@ -1,63 +1,59 @@
require("key/Rekey")
-- wraps.
rekey_visual("mwx", "s<delete><backspace><esc>p") -- unwrap once (select only stuff inside).
rekey_visual("mw\"", "s\"\"<esc>P") -- wrap in "".
rekey_visual("mw3\"", "s\"\"\"\"\"\"<esc>hhP") -- wrap in 3x "".
rekey_visual("mw'", "s''<esc>P") -- wrap in "".
rekey_visual("mw(", "s()<esc>P") -- wrap in ().
rekey_visual("mw)", "s()<esc>P") -- wrap in ().
rekey_visual("mw{", "s{}<esc>P") -- wrap in {}.
rekey_visual("mw}", "s{}<esc>P") -- wrap in {}.
rekey_visual("mw<", "s<><esc>P") -- wrap in {}.
rekey_visual("mw>", "s<><esc>P") -- wrap in {}.
rekey_visual("mw[", "s[]<esc>P") -- wrap in [].
rekey_visual("mw]", "s[]<esc>P") -- wrap in [].
rekey_visual("mw`", "s``<esc>P") -- wrap in ``.
rekey_visual("mw3`", "s``````<esc>hhP") -- wrap in 3x ``.
rekey_visual("mw*", "s**<esc>P") -- wrap in **.
rekey_visual("mw2*", "s****<esc>hP") -- wrap in 2x **.
rekey_visual("mw3*", "s******<esc>hhP") -- wrap in 3x **.
rekey_visual("mw ", "s <esc>P") -- wrap in spaces.
rekey_visual("<Leader>mwx", "s<delete><backspace><esc>p") -- unwrap once (select only stuff inside).
rekey_visual("<Leader>mw\"", "s\"\"<esc>P") -- wrap in "".
rekey_visual("<Leader>mw3\"", "s\"\"\"\"\"\"<esc>hhP") -- wrap in 3x "".
rekey_visual("<Leader>mw'", "s''<esc>P") -- wrap in "".
rekey_visual("<Leader>mw(", "s()<esc>P") -- wrap in ().
rekey_visual("<Leader>mw)", "s()<esc>P") -- wrap in ().
rekey_visual("<Leader>mw{", "s{}<esc>P") -- wrap in {}.
rekey_visual("<Leader>mw}", "s{}<esc>P") -- wrap in {}.
rekey_visual("<Leader>mw<", "s<><esc>P") -- wrap in {}.
rekey_visual("<Leader>mw>", "s<><esc>P") -- wrap in {}.
rekey_visual("<Leader>mw[", "s[]<esc>P") -- wrap in [].
rekey_visual("<Leader>mw]", "s[]<esc>P") -- wrap in [].
rekey_visual("<Leader>mw`", "s``<esc>P") -- wrap in ``.
rekey_visual("<Leader>mw3`", "s``````<esc>hhP") -- wrap in 3x ``.
rekey_visual("<Leader>mw*", "s**<esc>P") -- wrap in **.
rekey_visual("<Leader>mw2*", "s****<esc>hP") -- wrap in 2x **.
rekey_visual("<Leader>mw3*", "s******<esc>hhP") -- wrap in 3x **.
rekey_visual("<Leader>mw ", "s <esc>P") -- wrap in spaces.
-- rewraps. <delete><backspace>
rekey_visual("mwrx", "s<delete><backspace><delete><backspace><esc>p") -- unwrap once (select only stuff inside).
rekey_visual("mwr\"", "s<delete><backspace>\"\"<esc>P") -- wrap in "".
rekey_visual("mwr3\"", "s<delete><backspace>\"\"\"\"\"\"<esc>hhP") -- wrap in 3x "".
rekey_visual("mwr'", "s<delete><backspace>''<esc>P") -- wrap in "".
rekey_visual("mwr(", "s<delete><backspace>()<esc>P") -- wrap in ().
rekey_visual("mwr)", "s<delete><backspace>()<esc>P") -- wrap in ().
rekey_visual("mwr{", "s<delete><backspace>{}<esc>P") -- wrap in {}.
rekey_visual("mwr}", "s<delete><backspace>{}<esc>P") -- wrap in {}.
rekey_visual("mwr<", "s<delete><backspace><><esc>P") -- wrap in {}.
rekey_visual("mwr>", "s<delete><backspace><><esc>P") -- wrap in {}.
rekey_visual("mwr[", "s<delete><backspace>[]<esc>P") -- wrap in [].
rekey_visual("mwr]", "s<delete><backspace>[]<esc>P") -- wrap in [].
rekey_visual("mwr`", "s<delete><backspace>``<esc>P") -- wrap in ``.
rekey_visual("mwr3`", "s<delete><backspace>``````<esc>hhP") -- wrap in 3x ``.
rekey_visual("mwr*", "s<delete><backspace>**<esc>P") -- wrap in **.
rekey_visual("mwr2*", "s<delete><backspace>****<esc>hP") -- wrap in 2x **.
rekey_visual("mwr3*", "s<delete><backspace>******<esc>hhP") -- wrap in 3x **.
rekey_visual("mwr ", "s<delete><backspace> <esc>P") -- wrap in spaces.
rekey_visual("<Leader>mwrx", "s<delete><backspace><delete><backspace><esc>p") -- unwrap once (select only stuff inside).
rekey_visual("<Leader>mwr\"", "s<delete><backspace>\"\"<esc>P") -- wrap in "".
rekey_visual("<Leader>mwr3\"", "s<delete><backspace>\"\"\"\"\"\"<esc>hhP") -- wrap in 3x "".
rekey_visual("<Leader>mwr'", "s<delete><backspace>''<esc>P") -- wrap in "".
rekey_visual("<Leader>mwr(", "s<delete><backspace>()<esc>P") -- wrap in ().
rekey_visual("<Leader>mwr)", "s<delete><backspace>()<esc>P") -- wrap in ().
rekey_visual("<Leader>mwr{", "s<delete><backspace>{}<esc>P") -- wrap in {}.
rekey_visual("<Leader>mwr}", "s<delete><backspace>{}<esc>P") -- wrap in {}.
rekey_visual("<Leader>mwr<", "s<delete><backspace><><esc>P") -- wrap in {}.
rekey_visual("<Leader>mwr>", "s<delete><backspace><><esc>P") -- wrap in {}.
rekey_visual("<Leader>mwr[", "s<delete><backspace>[]<esc>P") -- wrap in [].
rekey_visual("<Leader>mwr]", "s<delete><backspace>[]<esc>P") -- wrap in [].
rekey_visual("<Leader>mwr`", "s<delete><backspace>``<esc>P") -- wrap in ``.
rekey_visual("<Leader>mwr3`", "s<delete><backspace>``````<esc>hhP") -- wrap in 3x ``.
rekey_visual("<Leader>mwr*", "s<delete><backspace>**<esc>P") -- wrap in **.
rekey_visual("<Leader>mwr2*", "s<delete><backspace>****<esc>hP") -- wrap in 2x **.
rekey_visual("<Leader>mwr3*", "s<delete><backspace>******<esc>hhP") -- wrap in 3x **.
rekey_visual("<Leader>mwr ", "s<delete><backspace> <esc>P") -- wrap in spaces.
-- markdown.
rekey_normal("mmx", ":s/- \\[ \\]/- \\[x\\]<C-l>/<cr>") -- mark checkbox.
rekey_normal("mm ", ":s/- \\[x\\]/- \\[ \\]<C-l>/<cr>") -- unmark checkbox.
rekey_visual("mmx", ":s/- \\[ \\]/- \\[x\\]<C-l>/<cr>") -- mark checkbox (multiline select),
rekey_visual("mm ", ":s/- \\[x\\]/- \\[ \\]<C-l>/<cr>") -- unmark checkbox (multiline select).
rekey_normal("mmp", "I  <esc>") -- insert paragraph (indent).
rekey_visual("mmb", "s****<esc>hP") -- make bold.
rekey_visual("mmi", "s**<esc>P") -- make italic.
rekey_visual("mms", "s~~~~<esc>hP") -- make strikethrough.
rekey_visual("mmr", "s``<esc>P") -- wrap in `` (reference).
rekey_visual("mmc", "s``````<esc>hhPa<cr><cr><esc><up>") -- wrap in 3x `` (code).
-- rekey_visual("mm>", ":s/^")
-- rekey_visual("mm<", "")
-- rekey_normal("mm>", "")
-- rekey_normal("mm<", "")
rekey_normal("<Leader>mmx", ":s/- \\[ \\]/- \\[x\\]<C-l>/<cr>") -- mark checkbox.
rekey_normal("<Leader>mm ", ":s/- \\[x\\]/- \\[ \\]<C-l>/<cr>") -- unmark checkbox.
rekey_visual("<Leader>mmx", ":s/- \\[ \\]/- \\[x\\]<C-l>/<cr>") -- mark checkbox (multiline select),
rekey_visual("<Leader>mm ", ":s/- \\[x\\]/- \\[ \\]<C-l>/<cr>") -- unmark checkbox (multiline select).
rekey_normal("<Leader>mmp", "I  <esc>") -- insert paragraph (indent).
rekey_visual("<Leader>mmb", "s****<esc>hP") -- make bold.
rekey_visual("<Leader>mmi", "s**<esc>P") -- make italic.
rekey_visual("<Leader>mms", "s~~~~<esc>hP") -- make strikethrough.
rekey_visual("<Leader>mmr", "s``<esc>P") -- wrap in `` (reference).
rekey_visual("<Leader>mmc", "s``````<esc>hhPa<cr><cr><esc><up>") -- wrap in 3x `` (code).
-- increment.
rekey_normal("mi", "<C-a>yyup<C-o>j") -- copy line and increment number under cursor.
rekey_normal("<Leader>mi", "<C-a>yyup<C-o>j") -- copy line and increment number under cursor.
-- select.
rekey_normal("ma", "ggVG") -- select all.
rekey_normal("<Leader>ma", "ggVG") -- select all.

View file

@ -1,3 +1,3 @@
require('key/Rekey')
require("key/Rekey")
rekey_normal('<Leader>0', '<cmd>WhichKey<cr>')
rekey_normal("?", "<cmd>WhichKey<cr>")

View file

@ -21,7 +21,7 @@ Command|Description
Command|Description
---|---
`archive [DIRS]`|Archive directories. All directories by default. Supports .archiveignore exclude file.
`archive_mt [DIRS]`|Archive using multiple threads. Uses 50% of free RAM. All directories by default. Supports .archiveignore exclude file.
`archive_mt [DIRS]`|Archive using multiple threads. Uses 75% of free RAM. All directories by default. Supports .archiveignore exclude file.
`archive_fast [DIRS]`|Archive directories with fast compression. All directories by default. Supports .archiveignore exclude file.
`archive_check [FILES]`|Check archives integrity. Checks all archives by default.
`archive_prune [NAME] [VERSIONS]`|Delete old versions of an archive. All archives with 1 version by default.
@ -51,7 +51,7 @@ Command|Description
Command|Description
---|---
`cdd <DIR>`|CD (back) to directory. Finds first directory that matches the input (case-insensitive).
`cdd <DIR>`|CD (back to) directory. Goes to the exact-match dir first. If no exact match found, it finds first directory that contains the input (case-insensitive).
## Checksum.
@ -220,6 +220,12 @@ Command|Description
`la [DIRS]`|List all files in dirs, incl. hidden files. Current dir by default.
`lla [DIRS]`|List all files in dirs, incl. hidden files, sorted by mtime. Current dir by default.
## Markdown.
Command|Description
---|---
`markdown_render <FILE.md>`|Render markdown in browser using Gitea API. Because I want consistency with Gitea web render. Works only inside LAN.
## Name.
Command|Description
@ -339,8 +345,8 @@ Command|Description
`td`|Detach from running session.
`tda`|Detach all other tmux clients.
`tl`|List running sessions.
`tns [NAME]`|Rename current session. Uses current dir name by default.
`tn [NAME]`|Assign name to window. Uses current dir name by default.
`tns [NAME]`|Assign name to session. Uses current dir name by default.
`tnw [NAME]`|Assign name to window. Uses current dir name by default.
`tk [NAME]`|Kill specified session. By default it kills `main` session.
`tka`|Kill all sessions.

View file

@ -28,6 +28,8 @@ Key|Action
`Super+j`|None.
`Super+k`|None.
`Super+l`|None.
`Super+p`|None.
`Super+n`|None.
## Tmux.
@ -57,6 +59,8 @@ Key|Action
`Meta+j`|Resize split to the down.
`Meta+k`|Resize split to the up.
`Meta+l`|Resize split to the right.
`Meta+p`|Scroll up.
`Meta+n`|Scroll down.
## Nvim.
@ -83,5 +87,7 @@ Key|Action
`Space+j`|Resize split to the down.
`Space+k`|Resize split to the up.
`Space+l`|Resize split to the right.
`Space+p`|None.
`Space+n`|None.
More info in [Nvim doc.](Nvim.md)