Some random useful scripts I wrote over the years
Run command in a pager without stdout and stderr mixing
Useful for commands output of which exceeds terminal buffer
or for terminals without scrolling, like st
cless cargo buildDependencies: less, unbuffer
Shortcut for inserting data from clipboard:
somecmd $(clipb)
somecmd `clipb`Dependencies: xclip
Script for cutting a picture into a grid to be printed on A4 (297x210mm) paper to be used for creating stencils for street art.
For example, to prepare a pic.png image to be made into a stencil for a 3x2m wall:
cut-stencil pic.png 3000x2000Dependencies: imagemagick
Git diff as a tree of files
difftree HEAD~Dependencies: git, tree
Run fzf in st terminal window
Dependencies: fzf, st
dmenu_run but with fzft
Dependencies: fzft
Script for generating the README.md for this repo:
./gendoc.sh > README.mdDependencies: grep, sed
Constructs github permalinks given filename and line number or range of lines.
Formats them as [src/file.js:3](...) markdown link and inserts into clipboard
gen-gh-permalink src/file.js 3 4You can use -s/--snippet parameter and pipe a piece of code into this script to get
[src/file.js:3](...):
```js
const a = 3;
...
```-style snippet.
Useful vim bindings:
nnoremap gH :execute '!' . 'gen-gh-permalink ' . shellescape(expand('%')) . ' ' . line(".")<cr>
vnoremap gH <esc>:execute '!' . 'gen-gh-permalink ' . shellescape(expand('%')) . ' ' . getpos("'<")[1] . ' ' . getpos("'>")[1]<cr>
vnoremap gHH <esc>:execute "'<,'>w !" . 'gen-gh-permalink -s ' . shellescape(expand('%')) . ' ' . getpos("'<")[1] . ' ' . getpos("'>")[1]<cr>Dependencies: git, grep, sed, xclip
Switch branches with fzf
Dependencies: fzf, git, sed
Merge branches quicker with fzf
Dependencies: fzf, git
Rebase branches quicker with fzf
Dependencies: fzf, git
Quickly create a PNG made with LaTeX. Useful for formulas.
Dependencies: dvipng, imagemagick, latex, vim
Take a snapshot of current environment, removing non-variables
mkenv .envrc
source .envrcDependencies: grep, sed
Preview plantuml files with feh
Dependencies: feh, plantuml
Use a hook file to rerun a command. Useful to trigger recompilation
whook .hook cargo buildExample of the vim binding triggering a hook
:nnoremap <F12> :call system('touch .hook')<cr>Dependencies: inotifywait, less, unbuffer