Skip to content

Instantly share code, notes, and snippets.

@nilox94
nilox94 / 1tb.sh
Created May 29, 2020 14:21
Create a 1TiB sparse file
dd if=/dev/zero of=1tb.img bs=1 count=0 seek=$((1<<40))
ls -lh 1tb.img
@nilox94
nilox94 / add-docker-group.sh
Created April 17, 2020 03:08
Add current user to docker group (or any other) and refresh group memberships in the current subshell
# add current user to group docker
sudo usermod -aG docker $USER
# replace current subshell with a new one with updated group memberships
exec sudo -sEu $USER
@nilox94
nilox94 / livecd2chroot.sh
Created April 7, 2020 01:55
chroot from live cd
#! /bin/bash
# select target root partition
if [ $1 ]
then
root=$1
else
# asuming the system is at the first ext partition
root=/dev/`lsblk -f | awk '
$2 ~ "ext" {
@nilox94
nilox94 / mute.sh
Created October 19, 2018 19:12
Executes a command and suppress its output
# mute
function mute()
{
${@:1} &> /dev/null
}
# mute completion -*- shell-script -*-
_mute()
@nilox94
nilox94 / colors.sh
Created June 13, 2018 18:28
Terminal colors for common outputs and bash prompts with a colored prompt example
# styles
declare -A styles=(
["normal"]="0"
["bold"]="1"
["dark"]="2"
["under"]="4"
["invert"]="7"
["background"]="8"
["negate"]="9"
)
@nilox94
nilox94 / wifi-hotspot
Created June 13, 2018 18:05
create a WiFi hotspot with `create_ap` bridging the wired network interface
#!/bin/sh
sudo create_ap `ifconfig -a | awk '/^w.*Ethernet/ { print $1; exit }` `ifconfig -a | awk '/^w.*Ethernet/ { print $1; exit }` $*
@nilox94
nilox94 / net-interfaces.sh
Last active February 18, 2019 22:32
Commands to list network interfaces and specifically wired and wireless interfaces
#!/bin/sh
function net-interfaces(){
echo `ip -c=never addr | gawk 'match($0, /[[:digit:]]+: ([[:alnum:]]+):/, m) { print m[1] }'`
}
function wireless() {
echo `ip -c=never addr | gawk 'match($0, /[[:digit:]]+: (w[[:alnum:]]+):/, m) { print m[1] }'`
}
@nilox94
nilox94 / bak.sh
Created June 13, 2018 16:30
Commands to backup and unbackup files rotating its names
#!/usr/bin/bash
function bak() {
name=${1%/}
prefix=${name%.bak}
if [[ $prefix == $name ]]; then
backup $name
else
unbackup $name
fi
@nilox94
nilox94 / battery
Created June 13, 2018 16:25
Animated progress bar of laptop battery in command line
#!/bin/sh
info=`acpi`
level=`echo $info | grep -Eo '[0-9]{,3}%' | tr -d '%'`
msg=`echo $info | sed 's/.*: //g'`
if [ $# = 0 ]
then columns=$((`tput cols` - 2))
else columns=$(( $1 - 2 ))
fi
@nilox94
nilox94 / crlf2lf
Created June 13, 2018 16:23
Converts CRLF to LF in a file or recursively in all files of a directory
#!/usr/bin/env python
import argparse, os, sys
(
NO_ERR,
READ_ERR,
WRITE_ERR,
BACKUP_ERR,
) = range(4)