Skip to content

Instantly share code, notes, and snippets.

Avatar

Jan Vitturi jan4843

View GitHub Profile
View auto-ls.sh
auto_ls() {
LASTPWD=${LASTPWD:-$PWD}
if [[ $PWD != "$LASTPWD" ]]; then
LASTPWD=$PWD
ls
fi
}
PROMPT_COMMAND="auto_ls${PROMPT_COMMAND:+; $PROMPT_COMMAND}"
@jan4843
jan4843 / set_apple_terminal.sh
Last active Sep 29, 2018
Set tab/window title, working document/directory in Terminal.app
View set_apple_terminal.sh
# From macOS /etc/bashrc_Apple_Terminal
percent_encode() {
local i ch hexch LC_CTYPE=C LC_ALL=
for ((i = 0; i < ${#1}; ++i)); do
ch="${1:i:1}"
if [[ "$ch" =~ [/._~A-Za-z0-9-] ]]; then
encoded+="$ch"
else
printf -v hexch "%02X" "'$ch"
# printf treats values greater than 127 as
@jan4843
jan4843 / send_escape_sequence.sh
Created Jan 3, 2018
Send escape sequence to terminal from tmux
View send_escape_sequence.sh
# From https://medium.freecodecamp.org/tmux-in-practice-integration-with-system-clipboard-bcd72c62ff7b
send_escape_sequence() {
if [[ -n $TMUX ]]; then
esc="\ePtmux;\e${1}\e\\"
pane_active_tty=$(tmux list-panes -F "#{pane_active} #{pane_tty}" | awk '$1=="1" { print $2 }')
printf "$esc" > "$pane_active_tty"
else
printf "$1"
fi
View percent_encode.sh
# from macOS /etc/bashrc_Apple_Terminal
percent_encode() {
local i ch hexch LC_CTYPE=C LC_ALL=
for ((i = 0; i < ${#1}; ++i)); do
ch="${1:i:1}"
if [[ "$ch" =~ [/._~A-Za-z0-9-] ]]; then
encoded+="$ch"
else
printf -v hexch "%02X" "'$ch"
@jan4843
jan4843 / archive.html
Created Nov 3, 2016
Jekyll Year Archive
View archive.html
---
layout: default
permalink: blog/archive/
---
<main>
{% for post in site.posts %}
{% unless post.next %}
<h1 class="modern">{{ post.date | date: '%Y' }}</h1>
<ul class="menu">
View detect-dismissed-notification.swift
func userNotificationCenter(center: NSUserNotificationCenter, didDeliverNotification notification: NSUserNotification) {
let priority = DISPATCH_QUEUE_PRIORITY_DEFAULT
dispatch_async(dispatch_get_global_queue(priority, 0)) {
var notificationStillPresent = true
while (notificationStillPresent) {
NSThread.sleepForTimeInterval(1)
notificationStillPresent = false
for deliveredNotification in NSUserNotificationCenter.defaultUserNotificationCenter().deliveredNotifications {
if deliveredNotification.identifier == notification.identifier {
notificationStillPresent = true
View style.sh
reset=$'\e[0m'
bold=$'\e[1m'
dim=$'\e[2m'
underline=$'\e[4m'
blink=$'\e[5m'
inverted=$'\e[7m'
hidden=$'\e[8m'
reset_bold=$'\e[21m'
reset_dim=$'\e[22m'
@jan4843
jan4843 / utis_tags.sh
Last active Aug 29, 2015
Get a list of Uniform Type Identifiers and their related tags in OS X
View utis_tags.sh
alias lsregister='/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister'
lsregister -dump |
awk '/uti: /{printf $2 ": "; while (getline && $1 != "tags:"); for (i=2; i<=NF; i++) printf $i " "; print ""}' |
sort -u
View shell_exec.py
class shell_exec:
def __init__(self, command, stdin=None):
from subprocess import Popen, PIPE
s = Popen(command, shell=True, stdout=PIPE, stderr=PIPE)
if stdin is not None:
s.stdin.write(stdin)
self.stdout, self.stderr = s.communicate()
self.exit_code = s.returncode
>>> s = shell_exec('echo Hello World!')
@jan4843
jan4843 / watch-folder.sh
Last active Aug 29, 2015
Trigger command on filesystem changes
View watch-folder.sh
fswatch -0 /path/to/watch |
while read -r -d ''
do
echo $REPLY
done
# Alternative
fswatch -0 /path/to/watch |
xargs -0 -n 1 -I {} \
echo {}
You can’t perform that action at this time.