Skip to content

Instantly share code, notes, and snippets.

@Konfekt
Konfekt / scope.sh
Last active September 27, 2024 19:37
scope.sh for text preview of office documents in ranger file manager (using .mailcap file from https://gist.github.com/Konfekt/9797372146e65a70a44c1e24a35ae0a2)
#!/usr/bin/env bash
# Uses ~/.mailcap from https://gist.github.com/Konfekt/9797372146e65a70a44c1e24a35ae0a2
# to read binary files
set -o noclobber -o noglob -o nounset -o pipefail
IFS=$'\n'
## If the option `use_preview_script` is set to `true`,
## then this script will be called and its output will be displayed in ranger.
@Konfekt
Konfekt / git-diff.md
Last active October 28, 2025 11:14
git diff common binary files

To diff common binary files in git using appropriate external converters such as unrtf, pandoc, docx2txt.pl, odt2txt, git-xlsx-textconv, git-xlsx-textconv.pl or pptx2md, add to ~/.config/git/config the lines

[diff]
    [diff "pdf"]
      binary = true
      textconv = "f(){ if command -v pdftotext >/dev/null 2>&1; then pdftotext -layout -enc UTF-8 -nopgbrk -q \"$1\" -; else cat \"$1\"; fi; }; f"
      # textconv = pdfinfo
      cachetextconv = true
@Konfekt
Konfekt / add-vim-help.sh
Last active August 31, 2021 12:46
add missing Vim help to Vim plug-in repos
#!/usr/bin/env bash
# description: add missing Vim help to Vim plug-in repos
# usage: add-vim-help.sh repos/*
# where repos/* are folders containing cloned repos without Vim help files
# needs:
# - md2vim from https://github.com/FooSoft/md2vim
# - hub from https://github.com/github/hub/ to open a Github pull request
@Konfekt
Konfekt / vim_mouse_2.ahk
Last active February 7, 2022 08:07
toggle vim_mouse_2.ahk (from https://github.com/4strid/vim_mouse_2.ahk) by Ctrl+; (similar to keynav on Linux)
#InstallKeybdHook
; vim_mouse_2.ahk
; vim (and now also WASD!) bindings to control the mouse with the keyboard
;
; Astrid Fesz-Nguyen
; 2019-04-14
;
; Last updated 2019-06-24
@Konfekt
Konfekt / view-attachments-mutt-windows-wsl.md
Last active May 9, 2023 19:27
View mail from Mutt in GUI Browser or E-Mail client under Windows, be it via WSL or Git Bash

To be able to view an E-Mail from Mutt under Windows either using the Windows Subsystem for Linux (WSL) or MSYS2 (as delivered with Git Bash)

  • in your default GUI E-Mail client by selecting the e-mail and hitting E(mail),
  • in your default GUI browser by selecting the attached HTML file and hitting B(rowser),

do as follows:

For WSL

Add to ~/.muttrc the lines

@Konfekt
Konfekt / git-xlsx-textconv.pl
Last active September 15, 2021 06:25
self-contained version of git-xlsx-textconv.pl for use in Git under Windows
This file has been truncated, but you can view the full file.
#!/usr/bin/env perl
# Self-contained version of git-xlsx-textconv.pl from
# https://github.com/yappo/p5-git-xlsx-textconv.pl
# for use in Git under Windows.
# created by [fatpacker](https://www.perladvent.org/2012/2012-12-14.html).
# In contrast xls2csv from https://github.com/xevo/xls2csv cannot be made
# self-contained by fatpacker because of binary dependencies (such as Iconv).
# This chunk of stuff was generated by App::FatPacker. To find the original
@Konfekt
Konfekt / diff.md
Last active October 18, 2021 08:21 — forked from PeterRincker/diff.md
:DiffOrig but smarter

:DiffOrig but smarter

This is an enhanced version of the snippet provided under :help diff-original-file.

Where the original :DiffOrig only shows differences between the buffer in memory and the file on disk, :Diff can be used in two ways:

  • against the file on disk, like the original, with:

    :Diff
    
@Konfekt
Konfekt / e.bat
Last active November 19, 2021 09:24
open %EDITOR% (or vim or notepad) using UTF-8 codepage in Microsoft Windows cmd shell
@echo off
SETLOCAL ENABLEEXTENSIONS
rem From https://superuser.com/questions/1118106/can-the-utf-8-code-page-identifier-65001-be-different-on-other-computers/1121076#1121076
rem capture output of chcp after colon
for /F "tokens=2 delims=:" %%G in ('chcp') do set "_chcp=%%G"
rem strip trailing dots
IF "%_chcp:~-1%"=="." set "_chcp=%_chcp:~0,-1%"
IF DEFINED EDITOR (
@Konfekt
Konfekt / langtool.bat
Created November 14, 2021 04:57
run language-tool in cmd using UTF-8 encoding
@echo off
setlocal
rem From https://languagetool.org/download/LanguageTool-stable.zip
set langtool_jar=%USERPROFILE%\bin\languagetool-commandline.jar
rem From https://superuser.com/questions/1118106/can-the-utf-8-code-page-identifier-65001-be-different-on-other-computers/1121076#1121076
rem capture output of chcp after colon
for /F "tokens=2 delims=:" %%G in ('chcp') do set "_chcp=%%G"
rem strip trailing dots
@Konfekt
Konfekt / tika.bat
Created November 14, 2021 05:11
run tika (= document text viewer) in cmd using UTF-8 encoding
@echo off
setlocal
rem From https://tika.apache.org/download.html
set tika_jar="%USERPROFILE%\bin\tika.jar"
rem From https://superuser.com/questions/1118106/can-the-utf-8-code-page-identifier-65001-be-different-on-other-computers/1121076#1121076
rem capture output of chcp after colon
for /F "tokens=2 delims=:" %%G in ('chcp') do set "_chcp=%%G"
rem strip trailing dots