Record Audio
RECORD="filename";arecord -v -f cd -t raw | lame -r -b 192 - ${RECORD}.mp3
Convert Video: Works with Whatsapp and Instagram
VIDEOCONVERT=00:00:00; TOOO=00:00:10; VID=input_video.avi; ffmpeg -i $VID -ss $WHATSAPP `if [[ "$TOOO" =~ [0-9][0-9]:[0-9][0-9]:[0-9][0-9] ]]; then echo "-to $TOOO"; fi` -y -c:v libx264 -pix_fmt yuv420p -preset slow -tune zerolatency -crf 19 -level 3.1 -movflags +faststart -c:a aac -b:a 128k -ar 44100 `echo "$VID" | sed -r "s/\..+$//g"`.out.mp4
Grab screen with sound: There are actually several unresolved ffmpeg bug reports, because using x11grab along with alsa will result in immediate buffer underruns. But some dude on Stackoverflow figured out that you have to use the -rtbufsize and -probesize parameters. Format works for Instagram and Whatsapp. Better use OBS Studio though.
SCREENCAPTURE="out"; GSIZE="1080x1080"; GOFF="0,0"; ffmpeg -rtbufsize 1500M -f alsa -i default -video_size $GSIZE -framerate 30 -rtbufsize 100M -f x11grab -i :0.0+$GOFF -probesize 10M -c:v libx264 -pix_fmt yuv420p -preset ultrafast -tune zerolatency -c:a aac -b:a 256k -ar 44100 ${SCREENCAPTURE}.mp4 -y
Set default apps: This is a total hack. Like you can see, it deletes only the default apps from your preferences and then pumps all files supported by the listed particular applications into it, starting with the most favorable. If you do not do this, then file extensions will be opened by alphabetical order, which is total garbage.
DEFAULT_APPS="org.gnome.FileRoller chromium thunderbird krita_raw org.gnome.Evince gimp gpicview libreoffice-writer libreoffice-base libreoffice-calc libreoffice-draw libreoffice-impress libreoffice-math libreoffice-xsltfilter mpv audacious org.gnome.gedit wine"; if [ -n "$ZSH_VERSION" ]; then setopt shwordsplit; fi; x="${HOME}/.config/mimeapps.list"; y="${HOME}/.local/share/applications/mimeapps.list"; if test -f "$y"; then rm "$y"; ln -s "$x" "$y"; fi; rm /tmp/Awwwk*.txt >& /dev/null; if not grep -q "\[Default Applications\]" "$x"; then echo "[Default Applications]" >> "$x"; fi; awk '/^\[.*\]/{x="/tmp/Awwwk"++i".txt";}{print > x;}' "$x" && { rm "$x"; for i in `seq 16`; do if test -f "/tmp/Awwwk${i}.txt" && grep -q "\[Default Applications\]" /tmp/Awwwk${i}.txt; then rm /tmp/Awwwk${i}.txt; fi; done; for i in `seq 16`; do if test -f "/tmp/Awwwk${i}.txt"; then cat /tmp/Awwwk${i}.txt >> $x; fi; done; echo "[Default Applications]" >> $x; for app in $DEFAULT_APPS; do grep "^MimeType=" /usr/share/applications/${app}.desktop | sed "s/^MimeType=//" | sed "s/;[[:space:]]*$//" | tr ';' '\n' | sed "s/^[[:space:]]*//" | sed "s/$/=${app}.desktop/" >> "$x"; done; echo -e "application/x-dosexec=wine.desktop\napplication/x-msdownload=wine.desktop\naudio/mpeg=mplayer.desktop\naudio/x-mpeg=mplayer.desktop" >> "$x"; echo "done"; }
Github commit: with auto credential insert and submodule update
GIT="."; GPASS="XXXX"; GUSER="ur username"; if ! git remote get-url origin | grep -q "$GPASS"; then git remote set-url origin "$(git remote get-url origin | sed "s#https://\(.\+:.\+@\)*github\.com#https://xx:sdf@github.com#g" |sed "s#^https://[^@]*@*#https://$GUSER:$GPASS@#g")"; fi ; git submodule update --remote --recursive; git add -u; git add * .*; git clean -f; git commit -m "$GIT"; git push
Kill every wine
WINEKILL=; WPIDS=""; for n in $(ps aux | grep "\(:\\\.*\.e[x]e\|"[^[:space:]]*wi[n]e[^[:space:]]*$"\)" | (cat && echo "$(ps aux | grep "\.exe" | grep defunct)") | (cat && echo "$(ps aux | grep "\.exe$")") | grep -os "^[^[:space:]]*[[:space:]]*[0-9]*" | grep -os "[0-9]*$" | tr '\n' ' '); do WPIDS="$n $WPIDS"; done; kill `echo "$WPIDS" | tr ' ' '\n'`; { sleep 3; kill -9 `echo "$WPIDS" | tr ' ' '\n'`; }
List installed packages by size on Archlinux
PACMANDISK=;paste <(pacman -Q | awk '{ print $1; }' | xargs pacman -Qi | grep 'Size' | awk '{ print $4$5; }') <(pacman -Q | awk '{print $1; }') | grep MiB | sort -n | column -t
List files and directories over 100MB
DU=;du -cshx ./* | grep "^\([0-9][0-9][0-9]M\|[0-9.]*G\)"
Backup from SSH: keep last 3 days + every 1st & 15th day of the month if they are no older than 60 days + mail on error
BACKUPDIR="/mnt/1/BACKUP/TVBOX/"; REMOTEDIR="/storage/srv/"; REMOTESSH="root@192.168.178.15"; BACKUPPREFIX="tvbox_"; KEEPDAYS="(01|15)"; IFNOTOLDERTHAN="60"; KEEPLAST="3"; ERR=-1; OUTFILE="${BACKUPPREFIX}backup_$(date +"%Y-%m-%d").tar.gz"; if cd "$BACKUPDIR"; then ssh "$REMOTESSH" tar czf - "$REMOTEDIR" > "$OUTFILE"; if [ $(/bin/stat -c%s "$OUTFILE") -gt 999999 ]; then while read line; do if [[ ! "$(date -d @$(/bin/stat -c %Y "$line") +%d)" =~ $KEEPDAYS ]]; then rm "$line"; fi; done < <(find . -type f -mtime +$(($KEEPLAST-1)) -name "$BACKUPPREFIX"'backup_*.gz' | sort -u); find . -type f -mtime +$IFNOTOLDERTHAN -name "$BACKUPPREFIX"'backup_*.gz' -delete; else ERR="Receiving data failed."; fi; else ERR="No backup dir."; fi; if [[ "$ERR" != "-1" ]]; then echo "ERROR: $ERR"; echo "" | mail -s "ERROR \"$ERR\" backup $OUTFILE" `whoami`@localhost; false; fi;
Set monitor brightness to half between 21:00 and 07:00, and full otherwise
BRIGHTNESS=1; if [ "$(($(date +%H)))" -gt 20 ] || [ "$(($(date +%H)))" -lt 7 ]; then BRIGHTNESS=0.5; fi; for OU in `xrandr | grep connected | grep -osa "^[^[:space:]]*"`; do xrandr --output $OU --brightness $BRIGHTNESS --gamma 1:1:1 ; done