Skip to content

Instantly share code, notes, and snippets.

View smuuf's full-sized avatar

Přemysl Karbula smuuf

View GitHub Profile
@smuuf
smuuf / ssh-multi-copy-id.sh
Last active December 20, 2018 12:10
Small BASH script which iterates over all hosts defined in SSH config and tries to ssh-copy-id your SSH ID to all of them.
#!/bin/bash
cd $(dirname $0)
CONF_PATH=~/.ssh/config
function title() {
echo "█ $1"
}
@smuuf
smuuf / git_status_in_function.sh
Last active November 30, 2018 10:47
git status in prompt function
#!/bin/bash
get_git_status() {
git_status=$(git status -s -u -v 2>/dev/null)
if [[ -z "$git_status" ]]; then return 0; fi
modified=$(echo "$git_status" | grep '^ M ' | wc -l)
deleted=$(echo "$git_status" | grep '^ D ' | wc -l)
untracked=$(echo "$git_status" | grep '^?? ' | wc -l)
echo "(~$modified -$deleted +$untracked) "
}
# Sets the color of next text output to be a random color based on hostname's md5 hash.
# (If the terminal supports true colour (RGB) colors.)
set_host_based_color() {
HOSTHASH=$(hostname | md5sum)
printf "\x1b[38;2;%d;%d;%dm" 0x${HOSTHASH:0:2} 0x${HOSTHASH:2:2} 0x${HOSTHASH:4:2}
}
# Example usage:
# PS1="[\$(set_host_based_color)\$(hostname)\033[0m]: "
# Use this to enable debugging for current terminal session.
# export XDEBUG_CONFIG="idekey=whatever"
[XDebug]
xdebug.remote_enable=1
xdebug.remote_autostart=0
xdebug.profiler_output_dir=/mnt/d/_produkce/_xdebug_profiles/
xdebug.profiler_output_name=callgrind.%t.out
xdebug.profiler_enable_trigger=1
#xdebug.idekey="asd"
@smuuf
smuuf / bestrsync.sh
Created April 4, 2019 21:00
Copy whole directories via rsync with resuming
rsync -e ssh -avzP --inplace (<src_host>:)<src_path> (<target_host>:)<target_path>
@smuuf
smuuf / .bashrc
Last active May 15, 2023 21:57
Pretty prompt alá smuuf
# smuuf.bashrc
# Prompt formatting
# 10:20:49 /etc
# [smuuf@smuuf-xubuntu]$
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1) /'
}
NC="$(tput sgr0)"
@smuuf
smuuf / wavtomp3.sh
Last active March 28, 2020 10:33
WAV to MP3 bash function
# Best to put this in your .bashrc
# .wav extension will be replaced with .mp3 automatically.
# Usage: wavtomp3 lorem_ipsum.wav
function wavtomp3() {
ffmpeg -i "$1" -vn -ar 44100 -ac 2 -b:a 320k "${1/.wav/.mp3}"
}
@smuuf
smuuf / gist:aa6b5bcf40fe075cca4cd84dbf9477ad
Last active May 27, 2020 13:26
Docker: WSL1 client WSL2 daemon
#!/bin/bash
# Have this in your client WSL1 ".bashrc" file.
WSL_DAEMON_DIST_NAME="Alpine" # WSL distribution name which has Docker daemon running in it.
export DOCKER_HOST=`wsl.exe -d $WSL_DAEMON_DIST_NAME eval ifconfig | grep -A 1 eth0 | grep -Po "\d+\.\d+\.\d+\.\d+" | head -n1`
@smuuf
smuuf / install_pypy.sh
Last active April 4, 2023 10:35
Simple install any version of pypy
# This is the name of archive taken from https://downloads.python.org/pypy/
PYPY_VER="pypy3.9-v7.3.11-linux64"
PYPY_VER_NUM=`echo ${PYPY_VER} | grep -oP "v(\d\.?)+" | sed -r 's/[v.]//g'`
cd ~
mkdir pypy
wget https://downloads.python.org/pypy/$PYPY_VER.tar.bz2 && tar -xvjf $PYPY_VER.tar.bz2
rm $PYPY_VER.tar.bz2
mv $PYPY_VER pypy/
sudo ln -s ~/pypy/$PYPY_VER/bin/pypy3 /usr/bin/pypy3-$PYPY_VER_NUM; chmod +x /usr/bin/pypy3-$PYPY_VER_NUM
@smuuf
smuuf / install_mariadb_service.sh
Created November 25, 2020 13:07
MariaDB 10.4 for WSL1 with sysVinit
# After installing MariaDB via apt, run this:
## Fix MySQL (MariaDB)
if [ ! -f "/etc/init.d/mysql" ]; then
sudo cp /usr/share/mysql/mysql.init /etc/init.d/mysql
sudo chmod a+x /etc/init.d/mysql
sudo service mysql restart
sudo mysql_secure_installation
sudo service mysql restart
fi