Skip to content

Instantly share code, notes, and snippets.

@amiryal
amiryal / hg-grep
Created December 7, 2010 10:21
A shell script that tries to emulate the most basic functionality of 'git grep' for Mercurial
#!/bin/bash
# Save the first argument as search pattern (the "what")
what=$1
shift
# Use colours if output goes to terminal
if [ -t 1 ]; then
use_color="--color=always"
fi
@amiryal
amiryal / git config
Last active February 20, 2024 21:02
Easily visualise Git merge.conflictstyle diff3 with meld, while preserving all information
[merge]
conflictstyle = diff3
tool = three_meld
[mergetool "three_meld"]
# Opens up four diff windows:
# LOCAL:MERGED, BASE:LOCAL, BASE:REMOTE, LOCAL:REMOTE
#
# Lets you edit the MERGED file (including original diff3 markers), showing
# you the final diff from LOCAL. For reference, you can look in the other
# windows to see how LOCAL and REMOTE are each different from BASE, as well
@amiryal
amiryal / branches_unmerged
Created August 21, 2011 15:44
Nice substitue for `git branch -r --no-merged`
#!/bin/sh
# This script nicely displays the remote Git branches not merged into
# the given branch, together with the list of commits they would introduce.
# Usage:
# For the current branch:
# branches_unmerged
# For the specified branch:
# branches_unmerged origin/master
@amiryal
amiryal / gist:1543873
Created December 31, 2011 12:29
Xubuntu (Xfce) fuzzy autocomplete menu window switcher keyboard shortcuts

To have the executables available in Ubuntu or Debian:

apt-get install suckless-tools

Keyboard shortcut command to choose from all windows:

/bin/sh -c 'wmctrl -l | while read i j k l; do echo $i $l; done | dmenu -i -l 16 | awk "{print \$1}" | while read i; do wmctrl -iR $i; done'

Keyboard shortcut command to choose from windows of the same process as currently active window:

@amiryal
amiryal / spawn_process.rb
Created October 23, 2013 13:35
Wrapper to Ruby spawn() with standard IO capture and basic exception handling.
module SpawnProcess
class NonSuccessStatus < StandardError
attr_accessor :status
def initialize(str, status)
@status = status
super(str)
end
end
def self.do(*args, &block)
@amiryal
amiryal / README.md
Last active December 13, 2019 20:09
Create branch on origin and track it locally

Script for creating tracking branches on origin

The script attempts to be agnostic to both git version and gitconfig settings.

To mimic the script in a git alias, run the following command:

git config -g alias.mkbranch '!foo() { git fetch origin &amp;&amp; git checkout -b "$1" "${2:-origin/master}" &amp;&amp; git push -u origin "$1":"$1"; }; foo'
@amiryal
amiryal / minimal.conf
Last active August 29, 2015 14:23
Minimal nginx http configuration
# Nginx will still complain about opening /var/log/nginx/error.log before
# switching to stderr. When shutting down, it will also complain about not
# being able to delete /dev/null.
daemon off;
error_log stderr info;
pid /dev/null;
events {
}
@amiryal
amiryal / written_files_tracking.rb
Created February 7, 2016 15:21
Ruby method to keep track of files written to while executing given block
class WrittenFilesTracking
def self.written_files
@@written_files
end
def self.start_with
@@start_with
end
def self.with(start_with:'./')
@amiryal
amiryal / passmenu.sh
Last active March 31, 2024 19:07
Script to copy username/password/TOTP to clipboard from dmenu-selected entry in Password Store
#!/bin/bash
# Adapted from https://git.zx2c4.com/password-store/tree/contrib/dmenu/passmenu
# at 0b2f803fe61992.
shopt -s nullglob globstar
mode=password
case "$1" in
'--username')
@amiryal
amiryal / nifi.service
Last active June 20, 2018 10:13 — forked from ddewaele/nifi.service
Nifi systemd service defintiion
# /etc/systemd/system/nifi.service
[Unit]
Description=Apache NiFi
After=network.target
[Service]
Type=simple
User=nifi
Group=nifi
ExecStart=/opt/nifi-latest/bin/nifi.sh run