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 # Shortcuts for commonly used commands
alias ll="ls -l $LS_OPTIONS" alias ll="ls -l $LS_OPTIONS"
alias la="ls -la $LS_OPTIONS" alias la="ls -la $LS_OPTIONS"
alias al=sl
alias x='startx; logout' alias x='startx; logout'
alias s='sudo -s -E' alias s='sudo -s -E'
alias po='eval $(proxy off)' alias po='eval $(proxy off)'
alias nw="sudo systemctl restart NetworkManager" alias nw="sudo systemctl restart NetworkManager"
alias mc="machines" alias mc="machines"
alias tracefiles="strace -f -t -e trace=file" 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 # Superseding commands with better ones if they are present
if which vim &> /dev/null; then if which vim &> /dev/null; then
alias vi='vim' alias vi='vim'

View file

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

View file

@ -3,13 +3,11 @@
import os import os
import argparse 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('dir', metavar='DIRECTORY', type=str, help="The directory to archive")
parser.add_argument('-d', '--dry', action='store_true')
args = parser.parse_args() args = parser.parse_args()
source = os.path.realpath(args.dir)
assert(os.path.isdir(source)), source + " must be a directory"
# Finding directories # Finding directories
assert('HOME' in os.environ), "Home directory unknown" assert('HOME' in os.environ), "Home directory unknown"
docs = os.path.realpath(os.path.join(os.environ['HOME'], 'Documents')) 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') arcs = os.path.join(docs, 'Archives')
assert(os.path.isdir(arcs)), "Archives folder not found" assert(os.path.isdir(arcs)), "Archives folder not found"
assert(source.startswith(docs)), "Directory is not in the document folder" def archive(docdir):
assert(not source.startswith(arcs)), "Directory is already in the archive folder" 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 if [ $GUI == 1 ]; then
# Desktop manager # Desktop manager
inst i3 i3lock dunst unclutter xautolock feh numlockx scrot xterm xclip 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 if [ $ARCH == 1 ]; then
inst xorg-xinit inst xorg-xinit
altInst polybar-git ttf-font-awesome autorandr-git keynav-enhanced pacmixer altInst polybar-git autorandr-git keynav-enhanced pacmixer
else else
# Compiling polybar # Compiling polybar
if ! which polybar > /dev/null; then if ! which polybar > /dev/null; then
@ -319,7 +320,7 @@ if [ $EXTRA == 1 ]; then
inst cmake clang llvm npm inst cmake clang llvm npm
# Extra CLI # Extra CLI
inst sl ffmpeg youtube-dl optipng syncthing ccache inst ffmpeg youtube-dl optipng syncthing ccache
if [ $ARCH == 1 ]; then if [ $ARCH == 1 ]; then
inst jq 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) # (executable)
# TODO Run in parallel # TODO Run in parallel
# TODO Lots of dupplicated code there
dir=${1:-$PWD} dir=${1:-$PWD}
total=$(mktemp) total=$(mktemp)
@ -20,7 +21,53 @@ function showtotal {
trap showtotal SIGTERM SIGINT SIGFPE 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 function replaceImg { # candidate original
# With bitmap verification
c="$1" c="$1"
o="$2" o="$2"
@ -61,11 +108,7 @@ function replaceImg { # candidate original
convert "$o" "$ppmo" convert "$o" "$ppmo"
if cmp --silent "$ppmo" "$ppmc"; then if cmp --silent "$ppmo" "$ppmc"; then
mv "$c" "$o" doReplace "$c" "$o"
saved=$(($os - $cs))
echo "→ $os ⇒ $cs (saved $saved bytes)"
newtotal=$(($(cat $total) + $saved))
echo -n $newtotal > $total
else else
echo "→ Candidate don't have the same bit map as original, skipping!" echo "→ Candidate don't have the same bit map as original, skipping!"
fi fi
@ -82,22 +125,9 @@ do
prog=$(mktemp --suffix .jpg) prog=$(mktemp --suffix .jpg)
jpegtran -copy all -progressive "$image" > "$prog" jpegtran -copy all -progressive "$image" > "$prog"
echo "→ Progressive done" echo "→ Progressive done"
optz=$(mktemp --suffix .jpg)
jpegtran -copy all -optimize "$image" > "$optz"
echo "→ Optimize done"
progs=$(wc -c "$prog" | cut -d' ' -f1) progs=$(wc -c "$prog" | cut -d' ' -f1)
optzs=$(wc -c "$optz" | cut -d' ' -f1) replace "$prog" "$image"
if [[ $progs -le $optzs ]]; then
echo "→ Using progressive"
replaceImg "$prog" "$image"
rm "$optz"
else
echo "→ Using optimized"
replaceImg "$optz" "$image"
rm "$prog"
fi
done <<< "$(find "$dir" -type f -iregex ".+.jpe?g$")" done <<< "$(find "$dir" -type f -iregex ".+.jpe?g$")"
@ -109,10 +139,10 @@ do
temp=$(mktemp --suffix .png) temp=$(mktemp --suffix .png)
cp "$image" "$temp" cp "$image" "$temp"
optipng -o7 -quiet "$temp" optipng -quiet "$temp"
echo "→ Optimize done" echo "→ Optimize done"
replaceImg "$temp" "$image" replace "$temp" "$image"
done <<< "$(find "$dir" -type f -iname "*.png")" done <<< "$(find "$dir" -type f -iname "*.png")"