Skip to content

Instantly share code, notes, and snippets.

@hh10k
hh10k / screen_pstree.pl
Created January 4, 2014 05:39
Do a pstree for each screen process.
#!/usr/bin/env perl
use warnings;
use strict;
opendir my $dir, "/var/run/screen/S-$ENV{USER}/";
foreach my $file (readdir $dir) {
my ($pid) = ($file =~ /^(\d+)\./);
next unless $pid;
print `pstree -p $pid`;
@hh10k
hh10k / storage.sh
Last active January 1, 2016 07:09
udev script and rules for automounting a disk under /media/ with its label
#!/bin/bash
# This file goes in /lib/udev/storage.sh
# Based on http://superuser.com/a/630937
# A matching /etc/udev/rules.d/85-storage-automount.rules should contain:
# ENV{DEVTYPE}=="partition", ENV{DEVNAME}!="/dev/mmcblk0p?", PROGRAM="/lib/udev/storage.sh mountpoint", ENV{MOUNTPOINT}="$result"
# ENV{MOUNTPOINT}!="", ACTION=="add", RUN+="/lib/udev/storage.sh add $env{MOUNTPOINT}"
# ENV{MOUNTPOINT}!="", ACTION=="remove", RUN+="/lib/udev/storage.sh remove $env{MOUNTPOINT}"
@hh10k
hh10k / howlong.sh
Last active December 25, 2015 06:08
How long will it take for a file to reach a target size?
#!/bin/bash
FILE=$1
TARGET_SIZE=$2
SIZES=()
INTERVAL=5
CURRENT_SIZE=($(wc -c "$FILE"))
while [[ $CURRENT_SIZE -lt $TARGET_SIZE ]]; do
SIZES=("${SIZES[@]}" $CURRENT_SIZE)
@hh10k
hh10k / bash_prompt.sh
Last active October 13, 2015 22:28
Bash prompt
function install_prompt {
local DEFAULT="\[\e[0m\]"
local RED="\[\e[31m\]"
local GREEN="\[\e[32m\]"
local YELLOW_BOLD="\[\e[1;33m\]"
local BLUE="\[\e[34m\]"
local WHITE="\[\e[37m\]"
local WHITE_BOLD="\[\e[1;37m\]"
local MAGENTA_BOLD="\[\e[1;35m\]"