Skip to content

Instantly share code, notes, and snippets.

@Konfekt
Konfekt / swap-alt-win-tab.ahk
Created April 27, 2024 20:04
Swap Win+Tab and Alt+Tab on Windows with Autohotkey v2
; Swap Alt+Tab and Win+Tab
; From https://www.autohotkey.com/boards/viewtopic.php?style=19&p=548067&sid=dfc532a1b55a0d25862c8ee98674e0db#p548067
#HotIf WinActive("ahk_class XamlExplorerHostIslandWindow")
*!Tab::Send("{Alt Down}{Right}")
~*Alt Up::Send("{Enter}")
#HotIf
*!Tab::#Tab
; From https://www.autohotkey.com/docs/v2/Hotkeys.htm#AltTabWindow
@Konfekt
Konfekt / bkp.sh
Created April 27, 2024 10:59
backup a file or restore it if it ends in a bkp extension
#!/usr/bin/env bash
# for each file, either back it up or restore it, in case it ends in a bkp extension
for f in "$@"; do
p="${f%/}"
[ "$p" != "${p%.bkp}" ] &&
cp --archive --interactive --update --verbose "$p" "${p%.bkp}" ||
cp -aiuv "${p}" "$p.bkp"
done; }
@Konfekt
Konfekt / scoop-apps.ps1
Last active May 2, 2024 12:34
Install a batch of useful scoop apps
<#
.SYNOPSIS
Script to install Scoop apps
.DESCRIPTION
Script uses scoop
.NOTES
**NOTE** Will configure the Execution Policy for the "CurrentUser" to Unrestricted.
Original Author: Mike Pruett
Date: October 18th, 2018
@Konfekt
Konfekt / single-file-git-with-vim.md
Last active April 21, 2024 15:25
Easily version control a single file under vim

Git was not designed for single-file projects, or managing multiple text files independently within a directory. However, below shell script and accompanying Vim commands work around it by creating a unique bare repository for each file (using a Git command to set a different location for each file's .git directory).

Command-Line Instructions

Copy the following script into a folder in $PATH, say as ~/bin/git1 (or g1) and mark it executable:

#!/usr/bin/env bash
@Konfekt
Konfekt / chmod-safe-sane.sh
Last active April 20, 2024 13:31
change permissions to be sane or safe inside a $dir by chmod-sane/safe $dir
#!/bin/sh
# Change file permissions to be sane or safe inside a directory $dir by
# chmod-sane/safe $dir
# For example, ~/.gnupg better be safe whereas ~/.cache can be sane.
# Set permissions in a specified directory to a
# standard, reasonable setting where directories are executable and readable by
# all users (755), and files are readable and writable by the owner, and readable
# by others (644). Additionally, files with execute permissions set for any user
@Konfekt
Konfekt / popup-arrow-scroll.vim
Created April 20, 2024 06:56
use arrow keys or Ctrl-J/K to scroll in Vim's popup window
" Use arrow keys or Ctrl-J/K to scroll in popup window.
" Also useful for terminals that maps the mouse wheel scrolls to arrow keys
" For example Urxvt with its Vtwheel extension
" From https://fortime.ws/blog/2020/03/14/20200312-01/
function! s:IsScrollPopup()
let winids = popup_list()
if empty(winids) | return {} | endif
let winid = winids[0]
@Konfekt
Konfekt / EvaluateAsComment.vim
Last active April 16, 2024 05:19
Add evaluation of selected code as comment
" From https://old.reddit.com/r/neovim/comments/1c3gf93/commentreplnvim_run_code_from_your_buffer_and/
"
" Add the following lines to `ftplugin/{python,sh,zsh,lua,perl, ...}.vim
" and call :EvaluateAsComment to add the evaluation of the selected lines as a comment:
"
" print(1+2)
"
" becomes
"
" # 3
@Konfekt
Konfekt / mapping-with-count-to-list-repo-or-all-files-altered-in-count-last-commits.vim
Created April 9, 2024 12:25
A mapping that uses FZF to list all files in a Git repo and takes a count to restrict to those altered in last <count> commits
" A mapping that uses FZF to list all files in a Git repo and takes a count to restrict to
" those altered in last <count> commits.
nnoremap <silent><expr> g. v:count ? ':<c-u>' . v:count . 'GFilesAltered<cr>' : ':<c-u>GFiles<cr>'
command! -count=1 GFilesAltered call fzf#vim#files('', fzf#vim#with_preview( {
\ 'source': 'git log HEAD --max-count=<count> --diff-filter=MA --name-only --pretty=format: | ' . s:filter,
\ 'options': '--multi --prompt "Files altered in last <count> commits: "',
\ } ))
" If Fugitive is installed, there's a fallback, here's a possible fallback
@Konfekt
Konfekt / RunOrRaise.ahk
Last active April 9, 2024 12:26
Autohotkey v2 Script to Run or Raise application using Shortcut
; Run or Raise Application using Shortcut
; From https://gist.github.com/dewaka/c494543b4cd2a2dcd09cc5a6aa0f7517 adapted to ah2
RunOrRaise(exePath, winID:="") {
if (winID == "") {
exeName := SubStr(exePath, InStr(exePath, "\", , -1)+1)
winID := "ahk_exe " . exeName
}
If not WinExist(winID) {
UserProfile := EnvGet("USERPROFILE")
@Konfekt
Konfekt / set.vim
Last active April 28, 2024 05:50
Use :Set! (instead of :set) to make setting persist in a modeline
function! Set(args, isPersistent) abort
" remove whitespaces surrounding =
let cmd = 'set ' . substitute(a:args, '\s*=\s*', '=', 'g')
execute cmd
if !a:isPersistent | return | endif
" append modeline
let commentstring = empty(&l:commentstring) ?
\ (empty(&g:commentstring) ? '# %s' : &g:commentstring) : &l:commentstring