Skip to content

Instantly share code, notes, and snippets.

@dragonauta
dragonauta / slpkg-tools.sh
Last active August 29, 2015 14:19
Search on Slackware repositories using slpkg tool
# This function takes first parameter ($1)
# to search on every enabled repository (on /etc/slpkg/slpkg.conf)
function slpkg-search() {
for r in $(slpkg repo-list | grep enabled | awk '{ print $1 }'); do
echo "Search in $r"
slpkg -l $r | grep -i $1
echo ""
done
}
@dragonauta
dragonauta / zsh-prompt.sh
Last active September 14, 2023 09:20
Zsh prompt change color if normal/root user
# This GIST should go inside your .zshrc file
# I use same .zshrc for normal and root user, so it's useful to change colors
#
# It will present PROMPT as: username@hostname dir $ or root@hostname dir #
# username on green chars
# root on red chars
# hostname on bold yellow chars
# directories on bold green chars
#
# RPROMPT should show a clock on the right
@dragonauta
dragonauta / laptop-dualhead.sh
Created April 12, 2015 02:30
Set dual head if monitor is connected to VGA output
#!/bin/bash
# Get state of VGA output: connected|disconnected
# you can get output's names with xrandr -q
VGA=$(xrandr -q | grep VGA1 | cut -f2 -d" ")
#
# Setting LVDS1 as primary (netbook display)
PRIMARY="--output LVDS1 --primary --mode 1024x600 --pos 0x0 --rotate normal"
#
# Setting VGA1 as secondary, placed right of LVDS1
SECONDARY="--output VGA1 --mode 1440x900 --pos 1024x0 --rotate normal"
@dragonauta
dragonauta / rtfm
Created April 12, 2015 03:02
RTFM function to find information about commands
function rtfm() { help $@ || $@ -h || $@ --help || man $@ || firefox -U "http://www.google.com/search?q=$@"; }
@dragonauta
dragonauta / dmenu-run.sh
Last active August 29, 2015 14:19
Dmenu script for [search|launch] commands
#!/bin/bash
# Red prompt ">" at bottom of screen, start typing your command.
# requires dmenu package.
/usr/bin/dmenu_run -fn "-*-fixed-*-*-*-*-14-*-*-*-*-70-*-*" -b -i -p ">" -nb '#2d2d2d' -nf '#eee' -sb '#d68637' -sf '#FFF'
@dragonauta
dragonauta / cvlc-streaming.sh
Last active August 29, 2015 14:19
Using CVLC for re-transmiting online streamings.
#!/bin/bash
# author: Diego 'dragonauta' Rucci
# version 0.2
# CVLC is part of VLC package. It's a CLI tool.
# Some (flash-based) streamings can't be mounted on icecast2.
# solution is to play them with VLC (or cvlc) and redirect output to an icecast2 mountpoint
# ChangeLog
# Added variables to easily reuse script
STREAMING=<put-your-online-streaming-url-here>
USER=<put-your-icecast-user-here>
# Search shell history with peco: https://github.com/peco/peco
# Adapted from: https://github.com/mooz/percol#zsh-history-search
if which peco &> /dev/null; then
function peco_select_history() {
local tac
(which gtac &> /dev/null && tac="gtac") || \
(which tac &> /dev/null && tac="tac") || \
tac="tail -r"
BUFFER=$(fc -l -n 1 | eval $tac | \
peco --layout=bottom-up --query "$LBUFFER")
@dragonauta
dragonauta / bash-variables
Created April 14, 2015 22:02
Bash variables
$# es la cantidad de parámetros
$@ representa todos los parámetros, util para recorrerlos con un bucle for.
$? contiene el valor de salida del último comando ejecutado
$$ es el PID del shell
$* todos los parámetros como una única palabra, debe ir encomillado "$*"
$- banderas pasadas al script utilizando set
$! PID del último comando en background
$_ pasa el argumento del comando anterior al actual
@dragonauta
dragonauta / rsync-ssh
Last active August 29, 2015 14:19
Sincronizar carpetas mediante ssh
#!/bin/bash
rsync -avz --delete -e ssh root@ip:/ruta/remota/ /ruta/local/
@dragonauta
dragonauta / tv.sh
Created April 20, 2015 13:50
Teamviewer from command line
#!/bin/bash
id=(your-id1 your-id2)
pass=(your-pass1 your-pass2)
tv=('Your PC1' 'Your PC2')
ITEMS=""
for item in {0..17}; do
ITEMS=$ITEMS" $item ${tv[$item]}"
echo $ITEMS
done