Je crée ce thread pour que chacun puisse partager le dernier script qu'il a créé pour se simplifier la vie, faire des trucs marrant au quoi que ce soit.
Il me semble pas avoir trouvé de sujet similaire sur le forum (j'en suis d'ailleurs étonné!), mais n'hésitez pas à me corriger dans le cas contraire.
Enfin trève de bavardages, je commence avec ces quelques scripts:
instagram.sh - Utilitaire d'aide à la prise de screenshot
(La prise en compte des gif est un peu foireuse)
Code : Tout sélectionner
#!/bin/bash
#
# 2013 Willy 'z3bra' Goiffon <willy at mailoo dot org>
#
# INSTAGRAM - screenshot taker / manager
#
# Licensed under WTFPL 2.0
#
# >> http://www.wtfpl.net/txt/copying/
#
IMAGE_DIR=~/usr/img # répertoire contenant les images
EXEC_UPLOAD=~/bin/upload # script utilisé pour uploader un fichier
SSHOT_DIR=${IMAGE_DIR}/wm # répertoire final du screenshot
VIEWER=meh # image viewer
function usage() {
cat <<SHBLAH
Usage : instagram [-tmuwh] [-g number] [-s screen] [filename.png]
-t : create thumbnail
-m : create one shot per head
-u : upload the file using $EXEC_UPLOAD <filename>
-w : take only a window for the shot (choose with pointer)
-h : display this help
-d path : save the shot in <path>
-g : create a gif (press ctrl-C to stop)
-s screen : use only the screen number <screen> for the shot
Also, do not give path to shot. They're saved to $SSHOT_DIR by default.
Configuration:
IMAGE_DIR : Where images are stored
SSHOT_DIR : Where to save your shots
EXEC_UPLOAD : Path to the script/program used to upload your shot
VIEWER : Program used to view the screenshot
SHBLAH
}
function upload() {
$EXEC_UPLOAD $1
}
[[ "$1" = "--help" ]] && usage && exit 0
# default window id
WINDOW='root'
while getopts ":htmuwd:gs:" opt; do
case $opt in
t) THUMB=1 ;;
m) MULTI=1 ;;
d) SSHOT_DIR=$OPTARG ;;
g) GIF=1 ;;
s) SCREEN=$OPTARG ;;
u) UPLOAD=1 ;;
w) WINDOW=$(xprop|grep 'window id'|cut -d\ -f7);;
h) usage; exit 0;;
?) echo "invalid option: -$OPTARG"; exit 1 ;;
esac
done
shift $((OPTIND-1))
if [[ -z "$1" ]]; then
OUTPUT="$USER-$(date +%Y-%m-%d).png"
else
OUTPUT=$1
fi
if [[ "$MULTI" = "1" ]] || [[ -n $SCREEN ]]; then
xdpyinfo -ext XINERAMA | sed '/^ head #/!d;s///' |
while IFS=' :x@,' read i w h x y; do
if [[ $SCREEN = "$i" ]] || [[ -z $SCREEN ]]; then
import -window ${WINDOW} -crop ${w}x$h+$x+$y $SSHOT_DIR/head_$i-$OUTPUT
[[ -n $THUMB ]] && import -window ${WINDOW} -thumbnail 25% -crop ${w}x$h+$x+$y $SSHOT_DIR/thumb-head_$i-$OUTPUT
fi
done
elif [ -n "$GIF" ]; then
mkdir $SSHOT_DIR/tmp
ffmpeg -f x11grab -s 1440x900 -r 25 -i :0.0 $SSHOT_DIR/tmp/out.mov
ffmpeg -i $SSHOT_DIR/tmp/out.mov -r 1 -f image2 $SSHOT_DIR/tmp/%05d.jpg
convert -delay 100 $SSHOT_DIR/tmp/*.jpg $SSHOT_DIR/${OUTPUT}
rm -rf $SSHOT_DIR/tmp
else
import -window ${WINDOW} $SSHOT_DIR/$OUTPUT
[[ -n $THUMB ]] && import -window ${WINDOW} -thumbnail 25% $SSHOT_DIR/thumb-${OUTPUT}
fi
if [[ "$UPLOAD" = "1" ]]; then
cd ${IMAGE_DIR}
upload wm/${OUTPUT}
fi
$VIEWER $SSHOT_DIR/$OUTPUT
Il permet de voir ses images dans son terminal grâve à w3m (trop cool!)
Code : Tout sélectionner
#!/bin/bash
#
# z3bra -- 2014-01-21
test -z "$1" && exit
W3MIMGDISPLAY="/usr/lib/w3m/w3mimgdisplay"
FILENAME=$1
FONTH=14 # Size of one terminal row
FONTW=8 # Size of one terminal column
COLUMNS=`tput cols`
LINES=`tput lines`
read width height <<< `echo -e "5;$FILENAME" | $W3MIMGDISPLAY`
max_width=$(($FONTW * $COLUMNS))
max_height=$(($FONTH * $(($LINES - 2)))) # substract one line for prompt
if test $width -gt $max_width; then
height=$(($height * $max_width / $width))
width=$max_width
fi
if test $height -gt $max_height; then
width=$(($width * $max_height / $height))
height=$max_height
fi
w3m_command="0;1;0;0;$width;$height;;;;;$FILENAME\n4;\n3;"
tput cup $(($height/$FONTH)) 0
echo -e $w3m_command|$W3MIMGDISPLAY
Code : Tout sélectionner
/*
* mcount.c -- z3bra 2013 <willy at mailoo dot org>
*
* Opens a directory and output the number of file found in this directory.
* Usefull to watch the number of mails in a folder and output it to a status
* bar.
*
*/
#include<stdio.h>
#include<stdlib.h>
#include<dirent.h>
#include<string.h>
#include<errno.h>
int main(int argc, char **argv)
{
int count = 0;
DIR* rep = NULL;
struct dirent *readFile = NULL;
if (argc > 1) {
rep = opendir(argv[1]);
} else {
fprintf(stderr, "usage: %s <directory>\n", argv[0]);
exit(1);
}
if(rep != NULL) {
while( (readFile = readdir(rep)) != NULL){
if(strcmp(readFile->d_name, ".") && strcmp(readFile->d_name, "..")){
count++;
}
}
if(closedir(rep) == -1){
exit (-1);
}
} else {
switch (errno) {
case EACCES:
fprintf(stderr,"bad permissions : %s/\n", argv[1]);
break;
case ENOTDIR:
fprintf(stderr, "not a directory : %s.\n", argv[1]);
break;
default:
fprintf(stderr, "erreur #%d\n",errno);
}
}
fprintf(stdout, "%u\n",count);
return 0;
}