oldest / newest

This commit is contained in:
Geoffrey Frogeye 2018-01-08 12:26:49 +01:00
parent f513500c29
commit 74c9d40126
7 changed files with 111 additions and 39 deletions

6
bashrc
View File

@ -51,17 +51,13 @@ alias systemclt=systemctl
# Shortcuts for commonly used commands
alias ll="ls -l $LS_OPTIONS"
alias la="ls -la $LS_OPTIONS"
alias al=sl
alias x='startx; logout'
alias s='sudo -s -E'
alias po='eval $(proxy off)'
alias nw="sudo systemctl restart NetworkManager"
alias mc="machines"
alias tracefiles="strace -f -t -e trace=file"
alias vpn="sudo systemctl start openvpn-client@$HOSTNAME"
alias vpno="sudo systemctl stop openvpn-client@$HOSTNAME"
alias vpns="sudo systemctl status openvpn-client@$HOSTNAME"
alias vpnr="sudo systemctl restart openvpn-client@$HOSTNAME"
# Superseding commands with better ones if they are present
if which vim &> /dev/null; then
alias vi='vim'

View File

@ -176,12 +176,11 @@ toggle-off-foreground = #55
[module/bbswitch]
type = custom/script
exec = grep -o '\w\+$' /proc/acpi/bbswitch | sed 's/OFF//' | sed 's/ON//'
exec-if = file /proc/acpi/bbswitch
exec = grep -o '\w\+$' /proc/acpi/bbswitch
exec-if = test -f /proc/acpi/bbswitch
interval = 5
format-prefix =
prefix =
format-foreground = ${theme.redF}
format-prefix-foreground = ${theme.redF}
[module/xbacklight]
type = internal/xbacklight

View File

@ -3,13 +3,11 @@
import os
import argparse
parser = argparse.ArgumentParser(description="Place a folder in ~/Documents in ~/Documents/Archive and symlink it")
parser = argparse.ArgumentParser(description="Place a folder in ~/Documents in ~/Documents/Archives and symlink it")
parser.add_argument('dir', metavar='DIRECTORY', type=str, help="The directory to archive")
parser.add_argument('-d', '--dry', action='store_true')
args = parser.parse_args()
source = os.path.realpath(args.dir)
assert(os.path.isdir(source)), source + " must be a directory"
# Finding directories
assert('HOME' in os.environ), "Home directory unknown"
docs = os.path.realpath(os.path.join(os.environ['HOME'], 'Documents'))
@ -17,7 +15,51 @@ assert(os.path.isdir(docs)), "Documents folder not found"
arcs = os.path.join(docs, 'Archives')
assert(os.path.isdir(arcs)), "Archives folder not found"
assert(source.startswith(docs)), "Directory is not in the document folder"
assert(not source.startswith(arcs)), "Directory is already in the archive folder"
def archive(docdir):
docdir = os.path.realpath(args.dir)
assert(os.path.isdir(docdir)), docdir + " must be a directory"
assert(docdir.startswith(docs)), "Directory is not in the document folder"
assert(not docdir.startswith(arcs)), "Directory is already in the archive folder"
reldir = os.path.relpath(docdir, docs)
print("ARC", reldir)
arcdir = os.path.join(arcs, reldir)
parentArcdir = os.path.realpath(os.path.join(arcdir, '..'))
parentDocdir = os.path.realpath(os.path.join(docdir, '..'))
linkDest = os.path.relpath(arcdir, parentDocdir)
# BULLSHIT
# If the directory exists
if os.path.isdir(arcdir):
return
# for f in os.listdir(arcdir):
# assert(os.path.isdir(f)), "Something unknown in Archive dir")
# archive(os.path.join(arcdir, f))
# If the directory doesn't exist, create the directories under it and move all the folder
else:
if args.dry:
print("mkdir -p", parentArcdir)
else:
os.makedirs(parentArcdir, exist_ok=True)
if args.dry:
print("mv", docdir, arcdir)
else:
os.rename(docdir, arcdir)
if args.dry:
print("ln -s", linkDest, docdir)
else:
os.symlink(linkDest, docdir)
def unarchive(arcdir):
return
archive(args.dir)

View File

@ -249,9 +249,10 @@ fi
if [ $GUI == 1 ]; then
# Desktop manager
inst i3 i3lock dunst unclutter xautolock feh numlockx scrot xterm xclip
curl "https://raw.githubusercontent.com/FortAwesome/Font-Awesome/a8386aae19e200ddb0f6845b5feeee5eb7013687/fonts/fontawesome-webfont.ttf" > ~/.local/share/fonts/fontawesome-webfont.ttf
if [ $ARCH == 1 ]; then
inst xorg-xinit
altInst polybar-git ttf-font-awesome autorandr-git keynav-enhanced pacmixer
altInst polybar-git autorandr-git keynav-enhanced pacmixer
else
# Compiling polybar
if ! which polybar > /dev/null; then
@ -319,7 +320,7 @@ if [ $EXTRA == 1 ]; then
inst cmake clang llvm npm
# Extra CLI
inst sl ffmpeg youtube-dl optipng syncthing ccache
inst ffmpeg youtube-dl optipng syncthing ccache
if [ $ARCH == 1 ]; then
inst jq

2
scripts/newestFile Executable file
View File

@ -0,0 +1,2 @@
#!/usr/bin/env bash
find -type f -printf '%T+ %p\n' | sort | tail "$@"

2
scripts/oldestFile Executable file
View File

@ -0,0 +1,2 @@
#!/usr/bin/env bash
find -type f -printf '%T+ %p\n' | sort | head "$@"

View File

@ -7,6 +7,7 @@
# (executable)
# TODO Run in parallel
# TODO Lots of dupplicated code there
dir=${1:-$PWD}
total=$(mktemp)
@ -20,7 +21,53 @@ function showtotal {
trap showtotal SIGTERM SIGINT SIGFPE
function doReplace { # candidate original
mv "$c" "$o"
saved=$(($os - $cs))
perc=$((100 * $saved / $os))
echo "→ $os ⇒ $cs (saved $saved bytes, or ${perc}%)"
newtotal=$(($(cat $total) + $saved))
echo -n $newtotal > $total
}
function replace { # candidate original
c="$1"
o="$2"
# File verifications
if [ ! -f "$o" ]; then
echo "→ Original is inexistant, skipping!"
return
fi
if [ ! -f "$c" ]; then
echo "→ Candidate is inexistant, skipping!"
return
fi
# Size verifications
cs=$(wc -c "$c" | cut -d' ' -f1)
os=$(wc -c "$o" | cut -d' ' -f1)
if [ $cs -le 0 ]; then
echo "→ Candidate is empty, skipping!"
rm "$c"
return
fi
if [ $cs -eq $os ]; then
echo "→ Candidate weight the same, skipping."
rm "$c"
return
fi
if [ $cs -gt $os ]; then
echo "→ Candidate is larger, skipping."
rm "$c"
return
fi
doReplace "$c" "$o"
}
function replaceImg { # candidate original
# With bitmap verification
c="$1"
o="$2"
@ -61,11 +108,7 @@ function replaceImg { # candidate original
convert "$o" "$ppmo"
if cmp --silent "$ppmo" "$ppmc"; then
mv "$c" "$o"
saved=$(($os - $cs))
echo "→ $os ⇒ $cs (saved $saved bytes)"
newtotal=$(($(cat $total) + $saved))
echo -n $newtotal > $total
doReplace "$c" "$o"
else
echo "→ Candidate don't have the same bit map as original, skipping!"
fi
@ -82,22 +125,9 @@ do
prog=$(mktemp --suffix .jpg)
jpegtran -copy all -progressive "$image" > "$prog"
echo "→ Progressive done"
optz=$(mktemp --suffix .jpg)
jpegtran -copy all -optimize "$image" > "$optz"
echo "→ Optimize done"
progs=$(wc -c "$prog" | cut -d' ' -f1)
optzs=$(wc -c "$optz" | cut -d' ' -f1)
if [[ $progs -le $optzs ]]; then
echo "→ Using progressive"
replaceImg "$prog" "$image"
rm "$optz"
else
echo "→ Using optimized"
replaceImg "$optz" "$image"
rm "$prog"
fi
replace "$prog" "$image"
done <<< "$(find "$dir" -type f -iregex ".+.jpe?g$")"
@ -109,10 +139,10 @@ do
temp=$(mktemp --suffix .png)
cp "$image" "$temp"
optipng -o7 -quiet "$temp"
optipng -quiet "$temp"
echo "→ Optimize done"
replaceImg "$temp" "$image"
replace "$temp" "$image"
done <<< "$(find "$dir" -type f -iname "*.png")"