Skip to content

Instantly share code, notes, and snippets.

View knu's full-sized avatar

Akinori Musha knu

  • Tokyo, Japan
  • 19:44 (UTC +09:00)
  • X @knu
View GitHub Profile
@knu
knu / barrier_karabiner.lua
Last active April 26, 2024 17:58
Barrier and Karabiner-Elements integration using Hammerspoon
knu = require("knu") -- https://github.com/knu/hs-knu
-- Switch between Karabiner-Elements profiles as Barrier enters a different host
do
-- Configure Barrier (https://github.com/debauchee/barrier) to output log to ~/Library/Logs/barrier.log
local logFile = os.getenv("HOME") .. "/Library/Logs/barrier.log"
local lineNo = 1
local host = nil
local defaultProfile = "Default"
local profileForHost = function (host)
@knu
knu / comparing_dot-separated_version_numbers.sh
Created April 8, 2024 13:25
Comparing dot-separated version numbers in shell script (one-liners)
# Comparing dot-separated version numbers in one line
# How to say $a >= $b using various tools and languages?
a=1.10.0
b=1.9.5
set -e
# POSIX
[ "$({ echo $a; echo $b; } | sort -n -t. -k1,1 -k2,2 -k3,3 | tail -n1)" = "$a" ]
@knu
knu / gist:111055
Created May 13, 2009 14:38
How to mass-rename tags and push them with Git
# Rename tags named foo-bar-#.#.# to v#.#.# and push the tag changes
git tag -l | while read t; do n="v${t##*-}"; git tag $n $t; git push --tags ; git tag -d $t; git push origin :refs/tags/$t ; done
@knu
knu / open-chromium
Last active March 10, 2024 06:21
JXA script to open a URL in a specified Chromium-based browser
#!/usr/bin/osascript -l JavaScript
// -*- javascript -*-
//
// open-chromium: Open a URL in a Chromium-based browser in a specified profile
//
// usage: open-chromium [(-a | --application) <app>] [(-p | --profile) <profile>] <url>
//
// <app>: "Chromium" (default), "Google Chrome", "Microsoft Edge", etc.
// <profile>: "Default", "Profile 1", etc.
//
#!/bin/sh
Verbose=
DryRun=
run() {
if [ -n "$DryRun" ]; then
echo "$*"
elif [ -n "$Verbose" ]; then
echo "$*"
@knu
knu / Importing ghq directories to projectile.md
Created November 29, 2023 12:19
Importing ghq directories to projectile.md

Create a timer that periodically imports ghq directories to projectile-known-projects.

(defun projectile-update-known-projects-with-ghq ()
  (interactive)
  (when (executable-find "ghq")
    (make-process :name "ghq"
                  :buffer (get-buffer-create "*ghq*")
@knu
knu / tweak-eval-defun.el
Created September 11, 2023 15:55
Get eval-defun to find a non-toplevel defun/defvar nearest to the point
;; (require 'smartparens)
(defun eval-defun:inner-def (orig-func &rest args)
(cl-letf*
(((symbol-function #'beginning-of-defun)
(lambda (&optional arg)
(let (pos)
(save-match-data
(cl-loop
do
@knu
knu / exit-minibuffer--prompt-for-make-directory.el
Last active September 5, 2023 13:20
Emacs snippet: Prompt user for make-directory when a non-existent directory is input in read-file-name
;; Prompt user for make-directory when a non-existent directory is input in read-file-name
(defun exit-minibuffer:prompt-for-make-directory (&rest args)
(and (cl-loop
for (_ func) in (backtrace-frames)
with n = 0
do (cl-case func
(read-file-name
(cl-return t))
(read-char-from-minibuffer
(cl-return nil))
@knu
knu / ijq
Created January 16, 2023 07:55
ijq - interactive jq
#!/bin/sh
#
# ijq - interactive jq
#
# usage: ijq [jq options] < file
#
# e.g. curl ... | ijq | tee output.json
#
# Copyright (c) 2023 Akinori MUSHA
#
@knu
knu / README.md
Last active December 23, 2022 07:56
knuスタイルAZIK for ATOK