From 44a65b01305a49e7c0192e3c19d06faae83a4a72 Mon Sep 17 00:00:00 2001 From: Pierre Neidhardt Date: Wed, 5 Mar 2014 10:58:42 +0100 Subject: [PATCH 01/10] Emacs: using guess-style for all prog modes --- .emacs.d/init.el | 2 ++ .emacs.d/main.el | 7 +++++-- .emacs.d/mode-cc.el | 1 - 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.emacs.d/init.el b/.emacs.d/init.el index 4bf194df..a5f7b616 100644 --- a/.emacs.d/init.el +++ b/.emacs.d/init.el @@ -112,6 +112,8 @@ Example: to assign some-function to C-i, use (when (fboundp 'po-find-file-coding-system) (modify-coding-system-alist 'file "\\.po\\'\\|\\.po\\." 'po-find-file-coding-system)) + + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Third-party tools (autoload 'guess-style-set-variable "guess-style" nil t) diff --git a/.emacs.d/main.el b/.emacs.d/main.el index d73e5cfe..3df08afe 100644 --- a/.emacs.d/main.el +++ b/.emacs.d/main.el @@ -109,9 +109,12 @@ mode-hook (lambda () (page-number-mode t) + (when (fboundp 'guess-style-guess-all) + (guess-style-guess-all)) ;; (setq show-trailing-whitespace t) (whitespace-mode)))) '(prog-mode-hook lua-mode-hook)) + ;; WARNING: this can break some configuration files needing whitespaces at the ;; end. ; (add-hook 'before-save-hook 'delete-trailing-whitespace) @@ -147,8 +150,8 @@ browse-url-browser-function 'browse-url-generic) (define-key my-keys-minor-mode-map (kbd "C-M-u") 'browse-url) -;; Default ispell dictionnay -;; (setq ispell-dictionary "fr") +;; Default ispell dictionnay. If not set, Emacs uses the current locale. +(setq ispell-dictionary "en") (define-key my-keys-minor-mode-map (kbd "") (lambda () (interactive) (ispell-change-dictionary "en"))) diff --git a/.emacs.d/mode-cc.el b/.emacs.d/mode-cc.el index 58d2fa1d..80ddb92b 100644 --- a/.emacs.d/mode-cc.el +++ b/.emacs.d/mode-cc.el @@ -76,7 +76,6 @@ restored." (lambda () (c-set-style "peter") (cc-set-compiler) - (guess-style-guess-all) (local-set-key (kbd "") 'cc-clean) (local-set-key (kbd "M-TAB") 'semantic-complete-analyze-inline) (local-set-key (kbd "C-c C-f") 'cc-fori) From 2a37429656cd1a1591a4859d6dbf318f59c5cd3f Mon Sep 17 00:00:00 2001 From: Pierre Neidhardt Date: Wed, 5 Mar 2014 11:14:16 +0100 Subject: [PATCH 02/10] Emacs: proper ranger call --- .emacs.d/main.el | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.emacs.d/main.el b/.emacs.d/main.el index 3df08afe..0fcadfa0 100644 --- a/.emacs.d/main.el +++ b/.emacs.d/main.el @@ -111,7 +111,6 @@ (page-number-mode t) (when (fboundp 'guess-style-guess-all) (guess-style-guess-all)) - ;; (setq show-trailing-whitespace t) (whitespace-mode)))) '(prog-mode-hook lua-mode-hook)) @@ -198,8 +197,9 @@ ;; Run ranger asynchronously. (define-key my-keys-minor-mode-map (kbd "C-x D") (lambda () (interactive) - (shell-command "urxvt -e ranger &") - (delete-windows-on "*Async Shell Command*"))) + (let ((term (getenv "TERMCMD"))) + (when (and (executable-find "ranger") (executable-find term)) + (start-process "dummy" nil term "-e" "ranger"))))) ;; Calendar ISO display. (setq calendar-week-start-day 1) @@ -271,7 +271,7 @@ ;; Multiple-Cursors (when (require 'multiple-cursors nil t) (setq mc/list-file (concat emacs-cache-folder "mc-lists.el")) - ;; Load the file at the new location + ;; Load the file at the new location. (load mc/list-file t) (global-unset-key (kbd "C-")) (define-key my-keys-minor-mode-map (kbd "C-") 'mc/add-cursor-on-click) From b65f2564ccdafe07bab46027e8e36c4298fcc43a Mon Sep 17 00:00:00 2001 From: Pierre Neidhardt Date: Wed, 5 Mar 2014 11:24:38 +0100 Subject: [PATCH 03/10] Emacs: comments on whitespace --- .emacs.d/main.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.emacs.d/main.el b/.emacs.d/main.el index 0fcadfa0..07a081db 100644 --- a/.emacs.d/main.el +++ b/.emacs.d/main.el @@ -118,7 +118,9 @@ ;; end. ; (add-hook 'before-save-hook 'delete-trailing-whitespace) (setq whitespace-style (quote (face trailing tab-mark))) -;; TODO: whitespace report-on-bogus does not seem to work properly. +;; TODO: whitespace report-on-bogus and cleanup do not seem to work properly. +;; Empty lines seems to be always true. Report is shown even when style is not +;; matching the errors. ; (setq whitespace-action '(report-on-bogus)) ;; Remove whitespaces on region, or whole file. From b3d9573c487d54d5061afeff6e7420abaaf3867d Mon Sep 17 00:00:00 2001 From: Pierre Neidhardt Date: Wed, 5 Mar 2014 15:59:15 +0100 Subject: [PATCH 04/10] Scripts: gnac init --- .scripts/gnac | 13 +++++++++++++ .scripts/phalt | 25 ------------------------- 2 files changed, 13 insertions(+), 25 deletions(-) create mode 100755 .scripts/gnac delete mode 100755 .scripts/phalt diff --git a/.scripts/gnac b/.scripts/gnac new file mode 100755 index 00000000..f0ac9575 --- /dev/null +++ b/.scripts/gnac @@ -0,0 +1,13 @@ +#!/bin/sh + +if [ "$1" = "-" ] || [ "$1" = "--help" ]; then + cat </dev/null 2>&1 && sessionclean - -## Poweroff / Reboot. -## If you do not want to get prompted for your password, configure sudo properly. -## TODO: use only "sudo halt -p"? - sudo $rawname -if command -v systemctl >/dev/null 2>&1; then - -else -fi From ea6e38465728db7e374eea60659424a3c37f93ab Mon Sep 17 00:00:00 2001 From: Pierre Neidhardt Date: Wed, 5 Mar 2014 22:19:34 +0100 Subject: [PATCH 05/10] pacsize: support for size units + auto db lookup --- .scripts/pacsize | 174 ++++++++++++++++++++++++++--------------------- 1 file changed, 97 insertions(+), 77 deletions(-) diff --git a/.scripts/pacsize b/.scripts/pacsize index 0791b67e..d9a7374b 100755 --- a/.scripts/pacsize +++ b/.scripts/pacsize @@ -16,133 +16,153 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -################################################################################ -## Helper functions. +readonly myname='pacsize' +readonly myver='4.1.2' calc_total () { - awk '{ - total += $1 - print + awk '{ + total += $1 + print } END { - printf ("%7s KIB TOTAL\n", total) + printf ("%7s KIB TOTAL\n", total) +}' +} + +error () { + echo "$@" >&2 +} + +## Print size and name. We strip the arguably useless decimals. This makes +## output lighter. +filter () { + awk -F ": " \ + '$0 ~ "^Name" { + pkg = $2 +} +$0 ~ "^Installed Size" { + gsub (/[\.,][^ ]*/, "") + split($2, a, " ") + printf ("%4d%s %s\n", a[1], a[2], pkg) }' } remove_duplicates () { - awk '! table[$0]++' + awk '! table[$0]++' } -usage() { +usage () { cat <' +} + opt_sort=false opt_all=false opt_total=false -while getopts ":ahnQSst" opt; do - case $opt in - a) - opt_all=true - db="Q" ;; - h) - usage "$0" - exit ;; - n) - opt_sort="sort -uk3" ;; - Q) - db="Q" ;; - S) - db="S" ;; - s) - opt_sort="sort -un" ;; - t) - opt_total="calc_total" ;; - ?) - usage "$0" - exit 1 ;; - esac +while getopts ":ahnstv" opt; do + case $opt in + a) + opt_all=true ;; + h) + usage "$0" + exit ;; + n) + opt_sort="sort -uk3" ;; + s) + opt_sort="sort -uh" ;; + t) + opt_total="calc_total" ;; + v) + version "$0" + exit ;; + ?) + usage "$0" + exit 1 ;; + esac done shift $(($OPTIND - 1)) -################################################################################ -## All-packages mode. We use a dedicated algorithm which is much faster than -## per-package mode. +## All-packages mode. +## We use a dedicated algorithm which is much faster than per-package mode. +## Unfortunately there is no easy way to select packages with this method. if $opt_all; then - DBPath="$(awk -F = '/^ *DBPath/{print $2}' /etc/pacman.conf)" - [ ! -d "$DBPath" ] && DBPath="/var/lib/pacman/" - [ ! -d "$DBPath/local/" ] && exit + DBPath="$(awk -F = '/^ *DBPath/{print $2}' /etc/pacman.conf 2>/dev/null)" + [ ! -d "$DBPath" ] && DBPath="/var/lib/pacman" - awk '/^%NAME%/ { - getline - pkg=$0 + if [ ! -d "$DBPath/local/" ]; then + error "Could not find local database in $DBPath/local/." + exit 1 + fi + + awk 'BEGIN { + split("B KiB MiB GiB TiB PiB EiB ZiB YiB", unit) +} +/^%NAME%/ { + getline + pkg=$0 } /^%SIZE%/ { - getline - size = $0 / 1024 - printf ("%6s KiB %s\n", size, pkg) + getline + size = $0 + i = 1 + while (size > 2048) { + size /= 1024 + i++ + } + printf ("%4d%s %s\n", size, unit[i], pkg) }' "$DBPath"/local/*/desc | ($opt_sort || cat) | ($opt_total || cat) - exit + exit fi -################################################################################ ## Per-package mode. if [ $# -eq 0 ]; then - echo "Missing argument." >&2 - usage "$0" - exit 1 + error "Missing argument." + usage "$0" + exit 1 fi if ! command -v pacman >/dev/null 2>&1; then - echo "'pacman' not found." >&2 - exit 1 + error "'pacman' not found." + exit 1 fi -## Locale. -LC_NAME="$(gettext pacman "Name")" -LC_SIZE="$(gettext pacman "Installed Size :" | sed 's/ *: *$//')" +{ + ## If package is not found locally (-Q), we use the sync database (-S). We + ## use LC_ALL=C to make sure pacman output is not localized. + buffer=$(LC_ALL=C pacman -Qi "$@" 2>&1 1>&3 3>&- | cut -f2 -d "'") + [ -n "$buffer" ] && LC_ALL=C pacman -Si $buffer +} 3>&1 | filter | ($opt_sort || remove_duplicates) | ($opt_total || cat) -## We use external variable for awk to fit current locales. In the following -## command, we strip the decimals. This makes output lighter. -pacman -${db}i "$@" 2>/dev/null | awk -F ": " \ - -v pkgsize="$LC_SIZE" -v pkgname="$LC_NAME" \ -'$0 ~ pkgname { - pkg = $2 -} -$0 ~ pkgsize { - gsub (/[\.,].*/, "") - printf ("%7s KiB %s\n", $2, pkg) -}' | ($opt_sort || remove_duplicates) | ($opt_total || cat) +# vim: set noet: From 2248c3cbb5514e9f4432244ab73c982dcc6d2632 Mon Sep 17 00:00:00 2001 From: Pierre Neidhardt Date: Thu, 6 Mar 2014 02:51:50 +0100 Subject: [PATCH 06/10] pacsize: various fixes --- .scripts/pacsize | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/.scripts/pacsize b/.scripts/pacsize index d9a7374b..0dfc47ef 100755 --- a/.scripts/pacsize +++ b/.scripts/pacsize @@ -118,8 +118,8 @@ shift $(($OPTIND - 1)) ## We use a dedicated algorithm which is much faster than per-package mode. ## Unfortunately there is no easy way to select packages with this method. if $opt_all; then - DBPath="$(awk -F = '/^ *DBPath/{print $2}' /etc/pacman.conf 2>/dev/null)" - [ ! -d "$DBPath" ] && DBPath="/var/lib/pacman" + DBPath="$(awk -F "=[ \t]*" '/^[ \t]*DBPath[ \t]*=/{gsub(/[ \t]*$/, "", $2); print $2}' /etc/pacman.conf 2>/dev/null)" + [ -z "$DBPath" ] && DBPath="/var/lib/pacman" if [ ! -d "$DBPath/local/" ]; then error "Could not find local database in $DBPath/local/." @@ -129,20 +129,18 @@ if $opt_all; then awk 'BEGIN { split("B KiB MiB GiB TiB PiB EiB ZiB YiB", unit) } -/^%NAME%/ { - getline - pkg=$0 +$0 == "%NAME%" { + getline pkg } -/^%SIZE%/ { - getline - size = $0 +$0 == "%SIZE%" { + getline size i = 1 while (size > 2048) { size /= 1024 i++ } printf ("%4d%s %s\n", size, unit[i], pkg) -}' "$DBPath"/local/*/desc | ($opt_sort || cat) | ($opt_total || cat) +}' "$DBPath"/local/*/desc | { $opt_sort || cat ;} | { $opt_total || cat ;} exit fi @@ -153,6 +151,7 @@ if [ $# -eq 0 ]; then exit 1 fi +## Remove this check if integrated to pacman. if ! command -v pacman >/dev/null 2>&1; then error "'pacman' not found." exit 1 @@ -163,6 +162,6 @@ fi ## use LC_ALL=C to make sure pacman output is not localized. buffer=$(LC_ALL=C pacman -Qi "$@" 2>&1 1>&3 3>&- | cut -f2 -d "'") [ -n "$buffer" ] && LC_ALL=C pacman -Si $buffer -} 3>&1 | filter | ($opt_sort || remove_duplicates) | ($opt_total || cat) +} 3>&1 | filter | { $opt_sort || remove_duplicates ;} | { $opt_total || cat ;} # vim: set noet: From cb030e871071969f9a2cf5587b625953e1fa81f9 Mon Sep 17 00:00:00 2001 From: Pierre Neidhardt Date: Thu, 6 Mar 2014 11:28:52 +0100 Subject: [PATCH 07/10] pacsize: minor fixes --- .scripts/pacsize | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.scripts/pacsize b/.scripts/pacsize index 0dfc47ef..39364193 100755 --- a/.scripts/pacsize +++ b/.scripts/pacsize @@ -33,15 +33,14 @@ error () { echo "$@" >&2 } -## Print size and name. We strip the arguably useless decimals. This makes -## output lighter. +## Print size and name. We round to the lowest integer, this makes output +## lighter. filter () { awk -F ": " \ '$0 ~ "^Name" { pkg = $2 } $0 ~ "^Installed Size" { - gsub (/[\.,][^ ]*/, "") split($2, a, " ") printf ("%4d%s %s\n", a[1], a[2], pkg) }' @@ -67,6 +66,7 @@ Options: -n: Sort output by name. -s: Sort output by size. -t: Print total. + -V: Show version information. Examples: @@ -90,7 +90,7 @@ opt_sort=false opt_all=false opt_total=false -while getopts ":ahnstv" opt; do +while getopts ":ahnstV" opt; do case $opt in a) opt_all=true ;; @@ -103,7 +103,7 @@ while getopts ":ahnstv" opt; do opt_sort="sort -uh" ;; t) opt_total="calc_total" ;; - v) + V) version "$0" exit ;; ?) From 1471942ed1253924abdf82d2fcc5201bda3c2231 Mon Sep 17 00:00:00 2001 From: Pierre Neidhardt Date: Thu, 6 Mar 2014 15:21:53 +0100 Subject: [PATCH 08/10] Scripts: colsum sums the specified column --- .scripts/colsum | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100755 .scripts/colsum diff --git a/.scripts/colsum b/.scripts/colsum new file mode 100755 index 00000000..7c9ba798 --- /dev/null +++ b/.scripts/colsum @@ -0,0 +1,20 @@ +#!/bin/sh + +COLUMN="1" +FORMAT="TOTAL: %s\n" + +if [ "$1" = "-h" ]; then + cat< Date: Thu, 6 Mar 2014 15:22:29 +0100 Subject: [PATCH 09/10] Scripts: currency converter --- .scripts/currency | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100755 .scripts/currency diff --git a/.scripts/currency b/.scripts/currency new file mode 100755 index 00000000..e4c72dd1 --- /dev/null +++ b/.scripts/currency @@ -0,0 +1,17 @@ +#!/bin/sh + +if [ $# -ne 3 ] || [ "$1" = "-h" ]; then + cat <' '/^1 / {print value * substr($3, 1, index($3," "))}' + + From 49e26ffd1ca33a4ad367b34640e349ecabe6e4a1 Mon Sep 17 00:00:00 2001 From: Pierre Neidhardt Date: Thu, 6 Mar 2014 15:35:52 +0100 Subject: [PATCH 10/10] Comments --- .scripts/browser-autostart | 4 +++- .scripts/zshcd | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.scripts/browser-autostart b/.scripts/browser-autostart index f3f4da3b..a2e6e3d8 100755 --- a/.scripts/browser-autostart +++ b/.scripts/browser-autostart @@ -1,6 +1,8 @@ #!/bin/sh -## Toggle shell browser autostart and launch terminal. +## Invoke a terminal while setting this environment variable. This way the shell +## can behave accordingly. This is useful to launch a program from X, which can +## then exit to shell, without closing the terminal. if [ -z "$TERMCMD" ]; then echo 'TERMCMD not set. Exiting.' diff --git a/.scripts/zshcd b/.scripts/zshcd index 48522a18..329c8ff7 100755 --- a/.scripts/zshcd +++ b/.scripts/zshcd @@ -1,5 +1,6 @@ #!/bin/sh -## Start zsh in the directory specified as first argument. +## Start zsh in the directory specified as first argument. Useful for file +## browsers to start shell in pointed folder. if [ ! -d "$1" ]; then zsh