From a79597c866607c715ae8008cbce5af56768dea89 Mon Sep 17 00:00:00 2001 From: Geoffrey Frogeye Date: Sun, 18 Dec 2016 15:10:40 +0100 Subject: [PATCH 01/10] Gopath --- bashrc | 1 + 1 file changed, 1 insertion(+) diff --git a/bashrc b/bashrc index b04ccf3..7eddb4a 100644 --- a/bashrc +++ b/bashrc @@ -40,6 +40,7 @@ export HISTFILESIZE=${HISTSIZE} export HISTCONTROL=ignoreboth export JAVA_FONTS=/usr/share/fonts/TTF export ANDROID_HOME=/opt/android-sdk +export GOPATH=$HOME/.go if [ -z $XDG_CONFIG_HOME ]; then export XDG_CONFIG_HOME=$HOME/.config From db7e8df5c68b4c204a7ee4bf4f55624265589b8e Mon Sep 17 00:00:00 2001 From: Geoffrey Frogeye Date: Sun, 18 Dec 2016 18:25:25 +0100 Subject: [PATCH 02/10] Clipboard manager, just what I needed --- config/i3/clipmenu | 52 ++++++++++++++++++ config/i3/clipmenud | 127 ++++++++++++++++++++++++++++++++++++++++++++ config/i3/config | 4 +- config/i3/dmenu_cmd | 2 +- 4 files changed, 183 insertions(+), 2 deletions(-) create mode 100755 config/i3/clipmenu create mode 100755 config/i3/clipmenud diff --git a/config/i3/clipmenu b/config/i3/clipmenu new file mode 100755 index 0000000..89935a1 --- /dev/null +++ b/config/i3/clipmenu @@ -0,0 +1,52 @@ +#!/bin/bash + +shopt -s nullglob + +# We use this to make sure the cache files are sorted bytewise +LC_COLLATE=C + +# Some people copy/paste huge swathes of text that could slow down dmenu +line_length_limit=500 + +declare -A selections +ordered_selections=() + +files=("$HOME/.clipmenu/"*) + +# We can't use `for ... in` here because we need to add files to +# ordered_selections from last to first -- that is, newest to oldest. Incoming +# clipboard entries have a ISO datetime prefixed to the front to aid in this. +for (( i=${#files[@]}-1; i>=0; i-- )); do + file=${files[$i]} + + # We look for the first line matching regex /./ here because we want the + # first line that can provide reasonable context to the user. That is, if + # you have 5 leading lines of whitespace, displaying " (6 lines)" is much + # less useful than displaying "foo (6 lines)", where "foo" is the first + # line in the entry with actionable context. + first_line=$(sed -n '/./{p;q}' "$file" | cut -c1-"$line_length_limit") + lines=$(wc -l < "$file") + + if (( lines > 1 )); then + first_line+=" ($lines lines)" + fi + + ordered_selections+=("$first_line") + selections[$first_line]=$file +done + +# It's okay to hardcode `-l 8` here as a sensible default without checking +# whether `-l` is also in "$@", because the way that dmenu works allows a later +# argument to override an earlier one. That is, if the user passes in `-l`, our +# one will be ignored. +chosen_line=$(printf '%s\n' "${ordered_selections[@]}" | uniq | $HOME/.config/i3/dmenu_cmd -l 8 -p "Copy" "$@") + +[[ $chosen_line ]] || exit 1 + +for selection in clipboard primary; do + if type -p xsel >/dev/null 2>&1; then + xsel --logfile /dev/null -i --"$selection" < "${selections[$chosen_line]}" + else + xclip -sel "$selection" < "${selections[$chosen_line]}" + fi +done diff --git a/config/i3/clipmenud b/config/i3/clipmenud new file mode 100755 index 0000000..98edd08 --- /dev/null +++ b/config/i3/clipmenud @@ -0,0 +1,127 @@ +#!/bin/bash + +hr_msg() { + printf -- '\n--- %s ---\n\n' "$1" >&2 +} + +debug() { + if (( DEBUG )); then + printf '%s\n' "$@" >&2 + fi +} + +print_debug_info() { + # DEBUG comes from the environment + if ! (( DEBUG )); then + return + fi + + local msg="${1?}" + + hr_msg "$msg" + + hr_msg Environment + env | LC_ALL=C sort >&2 + + cgroup_path=/proc/$$/cgroup + + if [[ -f $cgroup_path ]]; then + hr_msg cgroup + cat "$cgroup_path" >&2 + else + hr_msg 'NO CGROUP' + fi + + hr_msg 'Finished debug info' +} + +print_debug_info 'Initialising' + +cache_dir=$HOME/.clipmenu/ + +# It's ok that this only applies to the final directory. +# shellcheck disable=SC2174 +mkdir -p -m0700 "$cache_dir" + +declare -A last_data +declare -A last_filename + +while sleep "${CLIPMENUD_SLEEP:-0.5}"; do + print_debug_info 'About to run selection' + + for selection in clipboard primary; do + print_debug_info "About to do selection for '$selection'" + + if type -p xsel >/dev/null 2>&1; then + debug 'Using xsel' + data=$(xsel --logfile /dev/null -o --"$selection"; printf x) + else + debug 'Using xclip' + data=$(xclip -o -sel "$selection"; printf x) + fi + + debug "Data before stripping: $data" + + # We add and remove the x so that trailing newlines are not stripped. + # Otherwise, they would be stripped by the very nature of how POSIX + # defines command substitution. + data=${data%x} + + debug "Data after stripping: $data" + + if [[ $data != *[^[:space:]]* ]]; then + debug "Skipping as clipboard is only blank" + continue + fi + + if [[ ${last_data[$selection]} == "$data" ]]; then + debug 'Skipping as last selection is the same as this one' + continue + fi + + # If we were in the middle of doing a selection when the previous poll + # ran, then we may have got a partial clip. + possible_partial=${last_data[$selection]} + if [[ $possible_partial && $data == "$possible_partial"* ]]; then + debug "$possible_partial is a possible partial of $data" + debug "Removing ${last_filename[$selection]}" + rm -- "${last_filename[$selection]}" + fi + + filename="$cache_dir/$(LC_ALL=C date +%F-%T.%N)" + + last_data[$selection]=$data + last_filename[$selection]=$filename + + debug "Writing $data to $filename" + printf '%s' "$data" > "$filename" + + if ! (( NO_OWN_CLIPBOARD )) && [[ $selection != primary ]]; then + # Take ownership of the clipboard, in case the original application + # is unable to serve the clipboard request (due to being suspended, + # etc). + # + # Primary is excluded from the change of ownership as applications + # sometimes act up if clipboard focus is taken away from them -- + # for example, urxvt will unhilight text, which is undesirable. + # + # We can't colocate this with the above copying code because + # https://github.com/cdown/clipmenu/issues/34 requires knowing if + # we would skip first. + if type -p xsel >/dev/null 2>&1; then + xsel --logfile /dev/null -o --"$selection" | xsel -i --"$selection" + else + xclip -o -sel "$selection" | xclip -i -sel "$selection" + fi + fi + + if ! (( NO_TRANSFER_CLIPBOARD )) && [[ $selection != primary ]]; then + # Copy every clipboard content into primary clipboard + if type -p xsel >/dev/null 2>&1; then + xsel --logfile /dev/null -o --"$selection" | xsel -i --primary + else + xclip -o -sel "$selection" | xclip -i -sel primary + fi + fi + done +done diff --git a/config/i3/config b/config/i3/config index b53f462..e18e78f 100644 --- a/config/i3/config +++ b/config/i3/config @@ -38,6 +38,7 @@ bindsym $mod+F2 exec --no-startup-id ~/.config/i3/dmenu_run bindsym Mod1+F2 exec --no-startup-id ~/.config/i3/dmenu_run bindsym $mod+c exec --no-startup-id ~/.config/i3/passmenu +bindsym $mod+x exec --no-startup-id ~/.config/i3/clipmenu bindsym $mod+asterisk exec --no-startup-id ~/.config/i3/sshmenu bindsym $mod+dollar exec --no-startup-id ~/.config/i3/sshmenu root @@ -246,7 +247,7 @@ for_window [window_role="task_dialog"] floating enable for_window [urgent=latest] focus # focus urgent window -bindsym $mod+x [urgent=latest] focus +#bindsym $mod+x [urgent=latest] focus # reload the configuration file bindsym $mod+Shift+c reload @@ -377,6 +378,7 @@ exec --no-startup-id numlockx on # Activate Num lock #exec --no-startup-id conky -c $HOME/.conky/status # Desktop widget exec --no-startup-id unclutter # Hide mouse cursor after some time exec --no-startup-id dunst # Notifications +exec --no-startup-id $HOME/.config/i3/clipmenud # Clipboard manager # Autostart programs #exec --no-startup-id i3-msg 'workspace $WS8; exec firefox --new-window tweetdeck.twitter.com' diff --git a/config/i3/dmenu_cmd b/config/i3/dmenu_cmd index 139f7d3..e1d3599 100755 --- a/config/i3/dmenu_cmd +++ b/config/i3/dmenu_cmd @@ -1,2 +1,2 @@ #!/bin/sh -dmenu -fn 'DejaVu Sans Mono-8' -nb '#222222' -nf '#888888' -sb '#4E9C00' -sf '#FFFFFF' "$@" +dmenu -fn 'DejaVu Sans Mono-10' -nb '#222222' -nf '#888888' -sb '#4E9C00' -sf '#FFFFFF' -l 8 -f -i -h 19 "$@" From ea65323d7a80bc1a8a89dad6371855bb0a72303c Mon Sep 17 00:00:00 2001 From: Geoffrey Frogeye Date: Sun, 18 Dec 2016 18:25:59 +0100 Subject: [PATCH 03/10] Updated Ruby version Or I should write a script that automatically... Well, nope, I'm not in the mood to do that --- bashrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bashrc b/bashrc index b04ccf3..e0f2546 100644 --- a/bashrc +++ b/bashrc @@ -33,7 +33,7 @@ export VISUAL=vim export BROWSER=/usr/bin/qutebrowser export TZ=/usr/share/zoneinfo/Europe/Paris -export PATH="$PATH:$HOME/.local/bin:$HOME/.cabal/bin:$HOME/.gem/ruby/2.2.0/bin/" +export PATH="$PATH:$HOME/.gem/ruby/2.3.0/bin/" export LANG=fr_FR.utf8 export HISTSIZE=10000 export HISTFILESIZE=${HISTSIZE} From db60caeb72584c2b1bf0fd9f4e1f6209999d2def Mon Sep 17 00:00:00 2001 From: Geoffrey Frogeye Date: Mon, 19 Dec 2016 10:11:19 +0100 Subject: [PATCH 04/10] Opposite day --- bashrc | 1 - inputrc | 3 +++ scripts/installArch.sh | 6 +++--- scripts/installPreferences.sh | 34 +++++++++++++++++----------------- 4 files changed, 23 insertions(+), 21 deletions(-) diff --git a/bashrc b/bashrc index 7d0126a..2eb545c 100644 --- a/bashrc +++ b/bashrc @@ -63,7 +63,6 @@ shopt -s expand_aliases shopt -s extglob shopt -s histappend shopt -s hostcomplete -shopt -s autocd export LS_OPTIONS='--group-directories-first --time-style=+"%d/%m/%Y %H:%M" --color=auto --classify --human-readable' alias ls="ls $LS_OPTIONS" diff --git a/inputrc b/inputrc index e302a8d..c95c889 100644 --- a/inputrc +++ b/inputrc @@ -1,5 +1,8 @@ $include /etc/inputrc set editing-mode vi +set show-all-if-ambiguous on +set visible-stats on +set page-completions off $if mode=vi set keymap vi-command # these are for vi-command mode diff --git a/scripts/installArch.sh b/scripts/installArch.sh index 6a1d70a..cd72d49 100755 --- a/scripts/installArch.sh +++ b/scripts/installArch.sh @@ -36,7 +36,7 @@ function install-arch { prompt "Do you want yaourt on this machine?" local YAOURT=$? fi - if [ $YAOURT ]; then + if [ $YAOURT == 1 ]; then if [ -z $BAUERBILL ]; then prompt "Do you want bauerbill on this machine?" local BAUERBILL=$? @@ -71,7 +71,7 @@ function install-arch { inst wget pacman -Q yaourt &> /dev/null - if [[ $YAOURT && $? == 1 ]]; then + if [[ $YAOURT == 1 && $? == 1 ]]; then installPKGBUILD "https://aur.archlinux.org/cgit/aur.git/plain/PKGBUILD?h=package-query" installPKGBUILD "https://aur.archlinux.org/cgit/aur.git/plain/PKGBUILD?h=yaourt" fi @@ -81,7 +81,7 @@ function install-arch { fi pacman -Q bauerbill &> /dev/null - if [[ $BAUERBILL && $? == 1 ]]; then + if [[ $BAUERBILL == 1 && $? == 1 ]]; then sudo pacman -Sy manjaro-{hotfixes,keyring,release,system} --noconfirm gpg --recv-keys 1D1F0DC78F173680 diff --git a/scripts/installPreferences.sh b/scripts/installPreferences.sh index fd6175a..6417c6e 100755 --- a/scripts/installPreferences.sh +++ b/scripts/installPreferences.sh @@ -40,7 +40,7 @@ function install-preferences { # System detection if which pacman &> /dev/null; then ARCH=1 - if [ $ADMIN ]; then + if [ $ADMIN == 1 ]; then sudo pacman -Sy function installOne { # package pacman -Q $1 &> /dev/null @@ -83,7 +83,7 @@ function install-preferences { elif which dpkg &> /dev/null; then DEBIAN=1 - if [ $ADMIN ]; then + if [ $ADMIN == 1 ]; then apt-get update function installOne { # package STATUS=$(mktemp) @@ -146,16 +146,16 @@ function install-preferences { # Utils inst moreutils screen ncdu htop proxytunnel pass pv curl sshfs netcat - if [ $ARCH ]; then + if [ $ARCH == 1 ]; then inst pkgfile - if [ $ROOT ]; then + if [ $ROOT == 1 ]; then systemctl enable pkgfile-update.timer fi fi # Text editor inst vim - if [ $ARCH ]; then + if [ $ARCH == 1 ]; then inst ctags else inst exuberant-ctags @@ -164,27 +164,27 @@ function install-preferences { vim +PluginInstall +qall # YouCompleteMe (vim plugin) - if [ $DEBIAN ]; then + if [ $DEBIAN == 1 ]; then inst build-essential cmake python-dev python3-dev fi $HOME/.vim/bundle/YouCompleteMe/install.sh --clang-completer --tern-completer # Dev - if [ $DEBIAN ]; then + if [ $DEBIAN == 1 ]; then inst build-essential - elif [ $ARCH ]; then + elif [ $ARCH == 1 ]; then inst base-devel fi inst git cmake clang llvm # Common GUI - if [ $GUI ]; then + if [ $GUI == 1 ]; then # Desktop manager inst i3 i3lock dmenu dunst unclutter xautolock feh numlockx scrot - if [ $DEBIAN ]; then + if [ $DEBIAN == 1 ]; then inst suckles-tools - if [ ! $ROOT ]; then + if [ ! $ROOT == 1 ]; then ln -s $DEBLOC_ROOT/bin/dmenu{.xft,} fi else @@ -195,7 +195,7 @@ function install-preferences { fi # qutebrowser - if [ $DEBIAN ]; then + if [ $DEBIAN == 1 ]; then inst python3-lxml python-tox python3-pyqt5 python3-pyqt5.qtwebkit python3-sip python3-jinja2 python3-pygments python3-yaml TMP_DIR=$(mktemp -d) $(cd $TMP_DIR; wget --quiet https://qutebrowser.org/python3-pypeg2_2.15.2-1_all.deb) @@ -203,24 +203,24 @@ function install-preferences { instFile $TMP_DIR/*.deb rm -rf $TMP_DIR - elif [ $ARCH ]; then + elif [ $ARCH == 1 ]; then altInst qutebrowser fi fi - if [ $EXTRA ]; then + if [ $EXTRA == 1 ]; then # Extra CLI inst sl - if [ $ARCH ]; then + if [ $ARCH == 1 ]; then altInst pdftk fi # Extra GUI - if [ $GUI ]; then + if [ $GUI == 1 ]; then inst vlc gimp mpd vimpc - if [ $ARCH ]; then + if [ $ARCH == 1 ]; then inst simplescreenrecorder fi From 95d7a9a3e3f736a90a913f7bd216add6dcd15dfc Mon Sep 17 00:00:00 2001 From: Geoffrey Frogeye Date: Fri, 30 Dec 2016 14:27:02 +0000 Subject: [PATCH 05/10] Termux compatibility --- scripts/dotfiles.sh | 5 +- scripts/installPreferences.sh | 95 ++++++++++++++++++++++++++--------- 2 files changed, 73 insertions(+), 27 deletions(-) diff --git a/scripts/dotfiles.sh b/scripts/dotfiles.sh index 60b559d..d811342 100755 --- a/scripts/dotfiles.sh +++ b/scripts/dotfiles.sh @@ -1,4 +1,5 @@ -#!/usr/bin/env bash +#!/usrenv bash + # Handles dotfiles # Yes there are tons of similar scipts yet I wanted no more nor less than what I needed @@ -71,7 +72,7 @@ function _dotfiles-install-dir { # dir dir="${1%/}" dir="${dir#/}" - /bin/ls -A "$DOTREPO/$dir" | while read file; do + ls -A "$DOTREPO/$dir" | while read file; do if [[ -z "$dir" && $(echo $file | grep '^\(\.\|LICENSE\|README\)') ]]; then continue fi diff --git a/scripts/installPreferences.sh b/scripts/installPreferences.sh index 6417c6e..768fc09 100755 --- a/scripts/installPreferences.sh +++ b/scripts/installPreferences.sh @@ -18,6 +18,12 @@ function install-preferences { } # Don't ask for things that are already there + local TERMUX=0 + if [ -d /data/data/com.termux/files ]; then + local TERMUX=1 + local GUI=0 + fi + if which i3 &> /dev/null; then local GUI=1 fi @@ -83,19 +89,37 @@ function install-preferences { elif which dpkg &> /dev/null; then DEBIAN=1 - if [ $ADMIN == 1 ]; then - apt-get update + if [[ $ADMIN == 1 || $TERMUX == 1 ]]; then + if [ $TERMUX == 1 ]; then + DEBIAN=0 + apt update -y + else + sudo apt-get update -y + fi function installOne { # package + + # Finding out if it's already installed or not STATUS=$(mktemp) - LANG=C dpkg --list $1 &> $STATUS + LANG=C dpkg-query --status $1 &> $STATUS + local installed=0 if [ $? == 0 ]; then cat $STATUS | grep '^Status:' | grep ' installed' --quiet if [ $? == 0 ]; then - # TODO noconfirm - sudo apt-get install $1 + installed=1 fi fi rm -f $STATUS > /dev/null + + echo 101 $1 $installed + # Installing if it's not installed + if [ $installed == 0 ]; then + # TODO noconfirm + if [ $TERMUX == 1 ]; then + apt install $1 -y + else + sudo apt-get install $1 -y + fi + fi } function installFileOne { # file dpkg -i "$1" @@ -145,38 +169,59 @@ function install-preferences { # Common CLI # Utils - inst moreutils screen ncdu htop proxytunnel pass pv curl sshfs netcat - if [ $ARCH == 1 ]; then - inst pkgfile + inst grep sed sh tar + if [ $TERMUX == 1 ]; then + inst coreutils man termux-api openssl-tool if [ $ROOT == 1 ]; then - systemctl enable pkgfile-update.timer + inst tsu fi fi - - # Text editor - inst vim - if [ $ARCH == 1 ]; then - inst ctags - else - inst exuberant-ctags + inst moreutils screen ncdu htop proxytunnel pass pv curl wget sshfs netcat + if [[ $ARCH == 1 && $ROOT == 1 ]]; then + inst pkgfile + systemctl enable pkgfile-update.timer fi - git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim - vim +PluginInstall +qall - - # YouCompleteMe (vim plugin) - if [ $DEBIAN == 1 ]; then - inst build-essential cmake python-dev python3-dev - fi - $HOME/.vim/bundle/YouCompleteMe/install.sh --clang-completer --tern-completer # Dev if [ $DEBIAN == 1 ]; then inst build-essential elif [ $ARCH == 1 ]; then inst base-devel + else + inst make fi inst git cmake clang llvm + + # Text editor + if [ $GUI == 1 ]; then + inst gvim + else + if [ $TERMUX == 1 ]; then + inst vim-python + else + inst vim + fi + fi + if [ $DEBIAN == 1 ]; then + inst exuberant-ctags + else + inst ctags + fi + git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim + vim +PluginInstall +qall + + # YouCompleteMe (vim plugin) + if [ $DEBIAN == 1 || $TERMUX == 1 ]; then + inst python-dev python3-dev + fi + local YCM_ARGS="" + if [ $TERMUX == 0 ]; then + YCM_ARGS="$YCM_ARGS --clang-completer --tern-completer" + fi + + python $HOME/.vim/bundle/YouCompleteMe/install.python $YCM_ARGS + # Common GUI if [ $GUI == 1 ]; then @@ -210,7 +255,7 @@ function install-preferences { if [ $EXTRA == 1 ]; then # Extra CLI - inst sl + inst sl ffmpeg youtube-dl if [ $ARCH == 1 ]; then altInst pdftk From 940a4b41fae555deaa00019c3551f7089c3f455f Mon Sep 17 00:00:00 2001 From: Geoffrey Frogeye Date: Fri, 30 Dec 2016 15:35:25 +0100 Subject: [PATCH 06/10] Things --- bashrc | 6 ++---- scripts/installPreferences.sh | 3 ++- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/bashrc b/bashrc index 2eb545c..19e14ec 100644 --- a/bashrc +++ b/bashrc @@ -18,12 +18,10 @@ else fi export USER=$(whoami) -export HOSTNAME=$(cat /etc/hostname) -HOST=${HOSTNAME%%.*} -PS1="\[\e]2;\u@${HOST} \w\a\]\[\e[0;37m\][\[\e[0;${col}m\]\u\[\e[0;37m\]@\[\e[0;34m\]${HOST} \[\e[0;36m\]\W\[\e[0;37m\]]\$\[\e[0m\] " +PS1="\[\e]2;\u@\h \w\a\]\[\e[0;37m\][\[\e[0;${col}m\]\u\[\e[0;37m\]@\[\e[0;34m\]\h \[\e[0;36m\]\W\[\e[0;37m\]]\$\[\e[0m\] " PS2="> " PS3="+ " -PS4="+ " +PS4="- " # Vars diff --git a/scripts/installPreferences.sh b/scripts/installPreferences.sh index 6417c6e..ab614be 100755 --- a/scripts/installPreferences.sh +++ b/scripts/installPreferences.sh @@ -145,11 +145,12 @@ function install-preferences { # Common CLI # Utils - inst moreutils screen ncdu htop proxytunnel pass pv curl sshfs netcat + inst moreutils screen ncdu lsof htop proxytunnel pass pv curl sshfs netcat if [ $ARCH == 1 ]; then inst pkgfile if [ $ROOT == 1 ]; then systemctl enable pkgfile-update.timer + inst cronie fi fi From dc94ee80a1041fc1628f35496d28efced5ae7ce7 Mon Sep 17 00:00:00 2001 From: Geoffrey Frogeye Date: Sat, 31 Dec 2016 01:11:31 +0100 Subject: [PATCH 07/10] Optimize script --- scripts/index.sh | 3 + scripts/optimize.sh | 136 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 139 insertions(+) create mode 100755 scripts/optimize.sh diff --git a/scripts/index.sh b/scripts/index.sh index 5c2c984..55348d1 100755 --- a/scripts/index.sh +++ b/scripts/index.sh @@ -4,4 +4,7 @@ source ~/.scripts/debloc.sh source ~/.scripts/dotfiles.sh source ~/.scripts/installPreferences.sh source ~/.scripts/installArch.sh +function optimize { + bash ~/.scripts/optimize.sh +} alias beep=~/.scripts/beep.sh diff --git a/scripts/optimize.sh b/scripts/optimize.sh new file mode 100755 index 0000000..67af906 --- /dev/null +++ b/scripts/optimize.sh @@ -0,0 +1,136 @@ +#!/usr/bin/env bash + +# Optimizes everything the script can find in a folder, +# meaning it will compress files as much as possible, +# without losing any data (verification will be done +# in order to verify that no data has been done) +# (executable) + +# TODO Run in parallel + +dir=${1:-$PWD} +total=$(mktemp) +echo -n 0 > $total + +function showtotal { + echo "Total saved: $(cat "$total") bytes" + rm $total + exit +} + +trap showtotal SIGTERM SIGINT SIGFPE + +function replaceImg { # 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 + + # Bitmap verification + ppmc="$(mktemp --suffix .ppm)" + ppmo="$(mktemp --suffix .ppm)" + convert "$c" "$ppmc" + 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 + else + echo "→ Candidate don't have the same bit map as original, skipping!" + fi + rm "$ppmc" "$ppmo" + +} + +# JPEG (requires jpegtran) +while read image +do + echo Processing $image + + 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 + +done <<< "$(find $dir -type f -iregex ".+.jpe?g$")" + +# PNG (requires optipng) +while read image +do + echo Processing $image + + temp=$(mktemp --suffix .png) + cp "$image" "$temp" + optipng -o7 -quiet "$temp" + echo "→ Optimize done" + + replaceImg "$temp" "$image" + +done <<< "$(find $dir -type f -iname "*.png")" + +# SVG (requires svgo) +while read image +do + echo Processing $image + + temp=$(mktemp --suffix .svg) + cp "$image" "$temp" + svgo --quiet "$temp" + echo "→ Optimize done" + + replaceImg "$temp" "$image" + +done <<< "$(find $dir -type f -iname "*.svg")" + +# GIT (requires git) +find $dir -type d -name .git -print0 | while IFS= read -r -d '' dir; do + (cd "$dir"; git gc) +done + +showtotal From be5d768f6f7eb819f4f1e8cf63887b108c0cc4b5 Mon Sep 17 00:00:00 2001 From: Geoffrey Frogeye Date: Sat, 31 Dec 2016 01:35:13 +0100 Subject: [PATCH 08/10] Some dotfiles that took dust here --- .Xclients | 10 ++++++++++ .dmrc | 3 +++ .xsession | 10 ++++++++++ gtkrc-2.0 | 19 +++++++++++++++++++ 4 files changed, 42 insertions(+) create mode 100755 .Xclients create mode 100644 .dmrc create mode 100755 .xsession create mode 100644 gtkrc-2.0 diff --git a/.Xclients b/.Xclients new file mode 100755 index 0000000..e9ea196 --- /dev/null +++ b/.Xclients @@ -0,0 +1,10 @@ +#!/bin/sh + +# +# ~/.Xclients +# +# Executed by xdm/gdm/kdm at login +# + +/bin/bash --login -i ~/.xinitrc + diff --git a/.dmrc b/.dmrc new file mode 100644 index 0000000..f34186b --- /dev/null +++ b/.dmrc @@ -0,0 +1,3 @@ +[Desktop] +Language=fr_FR.utf8 +Session=i3 diff --git a/.xsession b/.xsession new file mode 100755 index 0000000..a16dc0b --- /dev/null +++ b/.xsession @@ -0,0 +1,10 @@ +#!/bin/sh + +# +# ~/.xsession +# +# Executed by xdm/gdm/kdm at login +# + +/bin/bash --login -i ~/.xinitrc + diff --git a/gtkrc-2.0 b/gtkrc-2.0 new file mode 100644 index 0000000..c016edc --- /dev/null +++ b/gtkrc-2.0 @@ -0,0 +1,19 @@ +# DO NOT EDIT! This file will be overwritten by LXAppearance. +# Any customization should be done in ~/.gtkrc-2.0.mine instead. + +include "/home/geoffrey/.gtkrc-2.0.mine" +gtk-theme-name="Greenbird" +gtk-icon-theme-name="Faenza-Green" +gtk-font-name="Sans 10" +gtk-cursor-theme-name="Menda-Cursor" +gtk-cursor-theme-size=0 +gtk-toolbar-style=GTK_TOOLBAR_BOTH +gtk-toolbar-icon-size=GTK_ICON_SIZE_LARGE_TOOLBAR +gtk-button-images=1 +gtk-menu-images=1 +gtk-enable-event-sounds=1 +gtk-enable-input-feedback-sounds=1 +gtk-xft-antialias=1 +gtk-xft-hinting=1 +gtk-xft-hintstyle="hintslight" +gtk-xft-rgba="rgb" From a1ab569bfb56961bba176ea3c790e34ef3ebc504 Mon Sep 17 00:00:00 2001 From: Geoffrey Frogeye Date: Sat, 14 Jan 2017 16:46:30 +0100 Subject: [PATCH 09/10] Changes to vimrc Note that I now allow arrow keys, because sometimes colleagues want to just scroll on my editor and they can't, I still use hjkl. --- vimrc | 47 +++++++++-------------------------------------- 1 file changed, 9 insertions(+), 38 deletions(-) diff --git a/vimrc b/vimrc index 79e7e37..ad633d1 100644 --- a/vimrc +++ b/vimrc @@ -19,8 +19,6 @@ Bundle 'Shougo/neosnippet-snippets' Plugin 'tpope/vim-surround' Plugin 'tpope/vim-fugitive' Plugin 'tpope/vim-repeat' -Plugin 'scrooloose/syntastic' -"Plugin 'terryma/vim-multiple-cursors' Plugin 'vim-airline/vim-airline' Plugin 'vim-airline/vim-airline-themes' Plugin 'airblade/vim-gitgutter' @@ -35,6 +33,7 @@ Plugin 'majutsushi/tagbar' Plugin 'wellle/targets.vim' Plugin 'Chiel92/vim-autoformat' Plugin 'Valloric/YouCompleteMe' +Plugin 'Raimondi/delimitMate' call vundle#end() " required filetype plugin indent on " required @@ -47,37 +46,12 @@ let g:ctrlp_custom_ignore = { \ 'link': 'SOME_BAD_SYMBOLIC_LINKS', \ } -""" SYNTASTIC """ - -set statusline+=%#warningmsg# -set statusline+=%{syntasticstatuslineflag()} -set statusline+=%* - -let g:syntastic_always_populate_loc_list = 0 -let g:syntastic_auto_loc_list = 0 -let g:syntastic_check_on_open = 1 -let g:syntastic_check_on_wq = 0 - -""" VIM-MULTIPLE-CURSORS """ - -let g:multi_cursor_use_default_mapping=0 -" Default mapping -let g:multi_cursor_next_key='' -let g:multi_cursor_prev_key='' -let g:multi_cursor_skip_key='' - -let g:multi_cursor_quit_key='' -" Map start key separately from next key -let g:multi_cursor_start_key='' -let g:multi_cursor_start_key='' -let g:multi_cursor_start_word_key='g' - """ VIM-AIRLINE """ set noshowmode set laststatus=2 let g:airline_powerline_fonts = 1 -let g:airline#extensions#syntastic#enabled = 1 +" let g:airline#extensions#syntastic#enabled = 1 let g:airline#extensions#tabline#enabled = 1 let g:airline_section_a = airline#section#create(['mode']) @@ -98,6 +72,10 @@ let g:NERDTreeIndicatorMapCustom = { \ "Unknown" : "?" \ } +""" YOUCOMPLETEME """ + +let g:ycm_global_ycm_extra_conf = '~/.config/ycm_extra_conf.py' + """ VIM SETTINGS """ @@ -129,6 +107,8 @@ set backspace=indent,eol,start set hidden set updatetime=250 +set cursorcolumn + syntax enable set background=dark @@ -158,15 +138,6 @@ if has('persistent_undo') set undofile endif -map -map -map -map -imap -imap -imap -imap -map ;; -imap ;; +imap jk map o From b8ead0532272c43fc9634613ee4c2334bb945d7e Mon Sep 17 00:00:00 2001 From: Geoffrey Frogeye Date: Sat, 14 Jan 2017 18:34:14 +0100 Subject: [PATCH 10/10] Too many things --- bashrc | 2 +- config/ycm_extra_conf.py | 4 ++++ scripts/machines.sh | 24 +++++++++++++++--------- scripts/optimize.sh | 12 ++++++------ scripts/svgo.yml | 5 +++++ vimrc | 1 + 6 files changed, 32 insertions(+), 16 deletions(-) create mode 100644 config/ycm_extra_conf.py create mode 100644 scripts/svgo.yml diff --git a/bashrc b/bashrc index 19e14ec..394d77b 100644 --- a/bashrc +++ b/bashrc @@ -111,8 +111,8 @@ alias fuck='eval $(thefuck $(fc -ln -1))' alias FUCK='fuck' # Command not found -[ -r /etc/profile.d/cnf.sh ] && . /etc/profile.d/cnf.sh [ -r /usr/share/doc/pkgfile/command-not-found.bash ] && . /usr/share/doc/pkgfile/command-not-found.bash +[ -r /etc/profile.d/cnf.sh ] && . /etc/profile.d/cnf.sh # Functions function clean { diff --git a/config/ycm_extra_conf.py b/config/ycm_extra_conf.py new file mode 100644 index 0000000..31b416f --- /dev/null +++ b/config/ycm_extra_conf.py @@ -0,0 +1,4 @@ +def FlagsForFile(filename, **kwargs): + return { + 'flags': ['-Wall', '-Wextra', '-lm'], + } diff --git a/scripts/machines.sh b/scripts/machines.sh index 8f4b240..3eb2a3f 100755 --- a/scripts/machines.sh +++ b/scripts/machines.sh @@ -79,13 +79,20 @@ function _machines-regenKey { openssl genrsa -out $MACHINES_CONFIG/machines.key 4096 chmod 600 $MACHINES_CONFIG/machines.key openssl req -key $MACHINES_CONFIG/machines.key -new -out $MACHINES_CONFIG/machines.csr - openssl x509 -req -in $MACHINES_CONFIG/machines.csr -signkey $MACHINES_CONFIG/machines.key -out $MACHINES_CONFIG/machines.crt + openssl x509 -req -days 1826 -in $MACHINES_CONFIG/machines.csr -signkey $MACHINES_CONFIG/machines.key -out $MACHINES_CONFIG/machines.crt _machines-pubFromCrt fi } +function _machines-verifyCertificate { + if openssl verify $MACHINES_CONFIG/machines.crt | grep -v 'error18' | grep 'error' --quiet; then + echo "Invalid certificate" + exit 1 + fi +} + function _machines-ensurePub { - if [ ! -f $MACHINES_CONFIG/machines.pub ]; then + if [ ! -f $MACHINES_CONFIG/machines.crt ]; then CERT_FILE=$(mktemp) echo "[INFO] Downloading certificate..." _machines-api cert > $CERT_FILE @@ -93,14 +100,15 @@ function _machines-ensurePub { prompt "Is this correct ?" if [ $? == 1 ]; then mv $CERT_FILE $MACHINES_CONFIG/machines.crt &> /dev/null - _machines-pubFromCrt - return 0 else echo "Certificate rejected." - return 1 - exit + exit 1 fi fi + _machines-verifyCertificate + if [ ! -f $MACHINES_CONFIG/machines.pub ]; then + _machines-pubFromCrt + fi } # SSH ACCESS KEYS @@ -115,6 +123,7 @@ function _machines-signAkey { # network } function _machines-getAkey { # network + _machines-ensurePub KEY_FILE=$(mktemp) SIGN_FILE=$(mktemp) _machines-api akey/$1 > $KEY_FILE @@ -275,9 +284,6 @@ function machines-setup { fi _machines-ensurePub - if [ $? != 0 ]; then - return 2 - fi # Variables read -p 'Machine name? ' name diff --git a/scripts/optimize.sh b/scripts/optimize.sh index 67af906..d329111 100755 --- a/scripts/optimize.sh +++ b/scripts/optimize.sh @@ -69,7 +69,7 @@ function replaceImg { # candidate original else echo "→ Candidate don't have the same bit map as original, skipping!" fi - rm "$ppmc" "$ppmo" + rm "$ppmc" "$ppmo" "$c" } @@ -98,7 +98,7 @@ do rm "$prog" fi -done <<< "$(find $dir -type f -iregex ".+.jpe?g$")" +done <<< "$(find "$dir" -type f -iregex ".+.jpe?g$")" # PNG (requires optipng) while read image @@ -112,7 +112,7 @@ do replaceImg "$temp" "$image" -done <<< "$(find $dir -type f -iname "*.png")" +done <<< "$(find "$dir" -type f -iname "*.png")" # SVG (requires svgo) while read image @@ -121,15 +121,15 @@ do temp=$(mktemp --suffix .svg) cp "$image" "$temp" - svgo --quiet "$temp" + svgo --quiet --config $HOME/.scripts/svgo.yml "$temp" echo "→ Optimize done" replaceImg "$temp" "$image" -done <<< "$(find $dir -type f -iname "*.svg")" +done <<< "$(find "$dir" -type f -iname "*.svg")" # GIT (requires git) -find $dir -type d -name .git -print0 | while IFS= read -r -d '' dir; do +find "$dir" -type d -name .git -print0 | while IFS= read -r -d '' dir; do (cd "$dir"; git gc) done diff --git a/scripts/svgo.yml b/scripts/svgo.yml new file mode 100644 index 0000000..99c6071 --- /dev/null +++ b/scripts/svgo.yml @@ -0,0 +1,5 @@ +plugins: + - mergePaths : false + - convertTransform : false + - cleanupNumericValues : false + diff --git a/vimrc b/vimrc index ad633d1..72b3a5c 100644 --- a/vimrc +++ b/vimrc @@ -139,5 +139,6 @@ if has('persistent_undo') endif imap jk +imap mù map o