Skip to content

Instantly share code, notes, and snippets.

Danilo Gómez nilox94

View GitHub Profile
@nilox94
nilox94 / 1tb.sh
Created May 29, 2020
Create a 1TiB sparse file
View 1tb.sh
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 Apr 17, 2020
Add current user to docker group (or any other) and refresh group memberships in the current subshell
View add-docker-group.sh
# 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 Apr 7, 2020
chroot from live cd
View livecd2chroot.sh
#! /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 Oct 19, 2018
Executes a command and suppress its output
View mute.sh
# mute
function mute()
{
${@:1} &> /dev/null
}
# mute completion -*- shell-script -*-
_mute()
@nilox94
nilox94 / colors.sh
Created Jun 13, 2018
Terminal colors for common outputs and bash prompts with a colored prompt example
View colors.sh
# styles
declare -A styles=(
["normal"]="0"
["bold"]="1"
["dark"]="2"
["under"]="4"
["invert"]="7"
["background"]="8"
["negate"]="9"
)
@nilox94
nilox94 / wifi-hotspot
Created Jun 13, 2018
create a WiFi hotspot with `create_ap` bridging the wired network interface
View wifi-hotspot
#!/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 Feb 18, 2019
Commands to list network interfaces and specifically wired and wireless interfaces
View net-interfaces.sh
#!/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 Jun 13, 2018
Commands to backup and unbackup files rotating its names
View bak.sh
#!/usr/bin/bash
function bak() {
name=${1%/}
prefix=${name%.bak}
if [[ $prefix == $name ]]; then
backup $name
else
unbackup $name
fi
@nilox94
nilox94 / battery
Created Jun 13, 2018
Animated progress bar of laptop battery in command line
View battery
#!/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 Jun 13, 2018
Converts CRLF to LF in a file or recursively in all files of a directory
View crlf2lf
#!/usr/bin/env python
import argparse, os, sys
(
NO_ERR,
READ_ERR,
WRITE_ERR,
BACKUP_ERR,
) = range(4)
You can’t perform that action at this time.