Initial commit bis : more files from /home/$USER/bin

This commit is contained in:
Pieds-Nus 2022-09-16 20:48:21 +00:00
parent 51366fefc8
commit 20f08193d2
5 changed files with 218 additions and 0 deletions

37
factorimods Normal file
View File

@ -0,0 +1,37 @@
#!/bin/bash
#Dependencies : you'll need a dmenu-like to run this script.
#On debian and debian-like distros (ubuntu, mint...), simply run:
# sudo apt install dmenu
#Edit this line to meet your installation
factorio_dir="/DATA/Games/factorio"
cd $factorio_dir/saves
#Ask the user to select a save
save=$(ls -t *.zip | grep -v autosave | rev | cut -d "." -f 2- | rev | dmenu)
test $? -ne 0 && echo "No save selected" && exit 1
#Check if a modlist exists for that save
if test -s mod-list.json_$save ; then
modlist=$save
else
#Otherwise, prompt to load another modlist
modlist=$(ls -t mod-list.json_* | cut -d "_" -f 2- | dmenu -p "No mod list found for savegame $save. Select mod list from available: ")
test $? -ne 0 && echo "No modlist selected" && exit 1
#And prompt to save it for later
echo -e "yes\nno" | dmenu -p "Save selected modlist for savegame $save ?" | grep "yes" && cp mod-list.json_$modlist mod-list.json_$save && modlist=$save
fi
#Link that modlist to the file read by factorio
ln -fs ../saves/mod-list.json_$modlist ../mods/mod-list.json
#Launch the game and the requested save
cd ..
echo "$factorio_dir/bin/x64/factorio --load-game $factorio_dir/saves/$save.zip"
$factorio_dir/bin/x64/factorio --load-game $factorio_dir/saves/$save.zip

42
unduplicator.sh Normal file
View File

@ -0,0 +1,42 @@
#/bin/bash
usage="\
$0 [-o OUTFILE] FILE1 [FILE2] [FILE3]...
Concatenate, sort and remove duplicate lines from a list of files.
If outfile isn't provided, will output to ./unduplicated.
"
test $# -eq 0 && echo -e "$usage\n\nError: At least one argument is needed" && exit 1
if test $1 = "-o" ; then
outfile="$2"
shift 2
else
outfile="./unduplicated"
fi
test $# -eq 0 && echo -e "$usage\n\nError: At least one file is required" && exit 1
file="$@"
#echo $file
input=`mktemp`
output=`mktemp`
#echo -e "Unduplicator:\n\tinfiles: $file\n\tinput:\t$input\n\toutput: $output\n\t outfile: $outfile"
sort "$file" > "$input"
#ls -lh $input $output
#i=0
while read -r line ; do
#i=$((i+1))
# echo "$i: $line ($file)"
test "$line" != "$linee" && echo "$line" >> $output # || echo "duplicate found : $line"
linee="$line"
done < "$input"
cat $output > $outfile
rm $input $output
exit 0

61
volume.sh Normal file
View File

@ -0,0 +1,61 @@
#/bin/bash
usage="\
$0 on|off|toggle|set|up|down [VALUE]
Simple binder between amixer, hotkeys and herbe notifications
"
test $# -eq 0 -o $# -gt 2 && echo -e "$usage\nOne or two arguments expected" && exit 1 ;
case $1 in
"up")
vol="$(amixer set Master ${2:-3}%+ | tail -n 1 | cut -d ' ' -f 7 | tr -d '[]%')" ;;
"down")
vol="$(amixer set Master ${2:-3}%- | tail -n 1 | cut -d ' ' -f 7 | tr -d '[]%')" ;;
"on")
vol="$(amixer set Master on | tail -n 1 | cut -d ' ' -f 7 | tr -d '[]%')" ;;
"off")
vol="$(amixer set Master off | tail -n 1 | cut -d ' ' -f 7 | tr -d '[]%')" ;;
"toggle")
vol="$(amixer set Master toggle | tail -n 1 | cut -d ' ' -f 7 | tr -d '[]%')" ;;
"set")
vol=$2
amixer -q set Master "$vol%" > /dev/null ;;
*)
echo "$usage"
echo "Unrecognized argument: $1"
exit 1 ;;
esac
ls /tmp/dsblok.pid &> /dev/null && /home/karsaell/Downloads/dsblocks/sigdsblocks/sigdsblocks 1 $vol
#echo vol: $vol
for i in {1..100..3} ; do
if test $i -lt $vol ; then
herbe="$herbe|"
else
herbe="$herbe "
fi
done
test -s /tmp/herbe_volume_pid && ( kill -s SIGUSR1 $(cat /tmp/herbe_volume_pid) ; rm /tmp/herbe_volume_pid )
amixer get Master | grep -q "%] \[on\]" && state=on || state=off
case $state in
on)
herbe.norm " $herbe" &
pid=$!
echo $pid >> /tmp/herbe_volume_pid
;;
off)
herbe.low " $herbe" &
pid=$!
echo $pid >> /tmp/herbe_volume_pid
;;
esac
wait $pid
test -e /tmp/herbe_volume_pid && echo -n `cat /tmp/herbe_volume_pid | grep -v $pid` > /tmp/herbe_volume_pid

36
wico Normal file
View File

@ -0,0 +1,36 @@
#!/bin/sh
#wico.sh : choose a wifi signal in range and try to connect to it
verb=0
if ( nmcli radio wifi | grep disabled > /dev/null ) ; then
test $verb -gt 0 && echo "Turning wifi on"
nmcli radio wifi on
sleep 1
fi
test $verb -gt 0 && echo "Scanning networks in range..."
nmcli device wifi rescan
ssid=$(nmcli -f IN-USE,SSID,BARS d wifi list | dmenu -l 8 | tr -s '*' ' ' | rev | cut -d ' ' -f 3- | rev | cut -d ' ' -f 2-)
test $verb -gt 0 && echo ssid: $ssid
test -z "$ssid" && echo "No ssid selected" && exit 1
if (nmcli d wifi connect "$ssid" | grep Error ) ; then
test $verb -gt 0 && echo "Password required"
herbe "Wifi "$ssid" : Password required" &
psk=$(echo Wifi: "$ssid" | dmenu -p "Please (re)type password")
test $verb -gt 0 && echo $psk
nmcli d wifi connect "$ssid" password "$psk"
fi
herbe "$(nmcli | grep wlp2s0:)"
exit $?

42
xpause Normal file
View File

@ -0,0 +1,42 @@
#!/bin/bash
#Usage
# xpause [resume]
# Click on a window to pause its process, or resume all such paused processes
#return status:
# 0 - Ok
# 1 - kill failed
# 2 - no pid found to resume
# 3 - failed to get pid from window
if test "$1" = "resume" ; then
if test -s /tmp/xpause ; then
kill -SIGCONT $(cat /tmp/xpause) || ( echo "xpause FAILED (kill)" ; exit 1 )
echo "xunpaused $(cat /tmp/xpause | wc -l)"
rm /tmp/xpause
exit 0
fi
echo "xpause FAILED" "No process to resume"
exit 2
fi
pid=$(xprop | grep PID | cut -d "=" -f 2)
test "$pid" -gt 0 || ( echo "xpause failed to get pid from window" ; exit 3 )
if test -s /tmp/xpause ; then
if grep "$pid" /tmp/xpause ; then
if kill -SIGCONT "$pid" ; then
echo "unpaused $pid"
exit 0
else
echo "xpause FAILED (kill)"
exit 1
fi
fi
fi
echo $pid >> /tmp/xpause
kill -s "SIGSTOP" $pid || ( echo "xpause FAILED (kill)" ; exit 1 )
echo "xpaused $pid"
exit 0