Merge remote-tracking branch 'origin/master'

master
Pierre Neidhardt 2014-03-06 18:32:41 +01:00
commit ff901964d0
10 changed files with 167 additions and 114 deletions

View File

@ -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)

View File

@ -109,14 +109,18 @@
mode-hook
(lambda ()
(page-number-mode t)
;; (setq show-trailing-whitespace t)
(when (fboundp 'guess-style-guess-all)
(guess-style-guess-all))
(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)
(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.
@ -147,8 +151,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 "<f5>")
(lambda () (interactive) (ispell-change-dictionary "en")))
@ -195,8 +199,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)
@ -268,7 +273,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-<down-mouse-1>"))
(define-key my-keys-minor-mode-map (kbd "C-<mouse-1>") 'mc/add-cursor-on-click)

View File

@ -76,7 +76,6 @@ restored."
(lambda ()
(c-set-style "peter")
(cc-set-compiler)
(guess-style-guess-all)
(local-set-key (kbd "<f9>") 'cc-clean)
(local-set-key (kbd "M-TAB") 'semantic-complete-analyze-inline)
(local-set-key (kbd "C-c C-f") 'cc-fori)

View File

@ -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.'

20
.scripts/colsum Executable file
View File

@ -0,0 +1,20 @@
#!/bin/sh
COLUMN="1"
FORMAT="TOTAL: %s\n"
if [ "$1" = "-h" ]; then
cat<<EOF
Usage: ${0##*/} [COLUMN] [FORMAT]
Sum COLUMN (default to column $COLUMN) and output result with format FORMAT
(default to $FORMAT).
EOF
exit
fi
[ $# -ge 1 ] && COLUMN="$1" && shift
[ $# -ge 1 ] && FORMAT="$1"
awk -v format="$FORMAT" '{total += $'$COLUMN'; print} END {printf format, total}'

17
.scripts/currency Executable file
View File

@ -0,0 +1,17 @@
#!/bin/sh
if [ $# -ne 3 ] || [ "$1" = "-h" ]; then
cat <<EOF
Usage: ${0##*/} VALUE IN-CURRENCY OUT-CURRENCY
Convert VALUE from IN-CURRENCY to OUT-CURRENCY.
CURRENCY is a 3-letters code like EUR, SEK, USD, etc.
EOF
exit
fi
curl -sA "Mozilla/5.0" "http://www.google.com/finance?q=$2$3" | \
awk -v value=$1 -F '<|>' '/^1 / {print value * substr($3, 1, index($3," "))}'

13
.scripts/gnac Executable file
View File

@ -0,0 +1,13 @@
#!/bin/sh
if [ "$1" = "-" ] || [ "$1" = "--help" ]; then
cat <<EOF
Usage: ${0##*/} [FILES]
Grep non-ascii characters. If no files are provided, use stdin.
EOF
exit
fi
perl -ne 'chomp; print $_, "\n" if /[[:^ascii:]]/'

View File

@ -16,133 +16,152 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
################################################################################
## 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 round to the lowest integer, this makes output
## lighter.
filter () {
awk -F ": " \
'$0 ~ "^Name" {
pkg = $2
}
$0 ~ "^Installed Size" {
split($2, a, " ")
printf ("%4d%s %s\n", a[1], a[2], pkg)
}'
}
remove_duplicates () {
awk '! table[$0]++'
awk '! table[$0]++'
}
usage() {
usage () {
cat <<EOF
Usage: ${1##*/} [OPTIONS] PACKAGES
${1##*/} -a [OPTIONS]
Display package sizes. Duplicates are removed if any. Output can be sorted by
name or size. A grand total can be printed at the end. Both the sync and the
local databes can be used for lookup.
Display the size of PACKAGES. Duplicates are removed if any. The local database
is queried first; if the package is not found, the sync database is then used
for lookup.
Options:
-a: All installed packages. Implies -Q.
-a: Process all installed packages.
-h: Show this help.
-n: Output is sorted by name.
-Q: Use local database. It speeds up queries and allows displaying
size of local packages not available in repos.
-S: Use sync database. It is slower but allows to display size of
non-installed packages.
-s: Output is sorted by size.
-n: Sort output by name.
-s: Sort output by size.
-t: Print total.
-V: Show version information.
Examples:
${1##*/} -ast
$ ${1##*/} -ast
Convenient way to keep track of big packages.
${1##*/} -Q \$(pactree -ld1 linux)
$ ${1##*/} \$(pactree -ld1 linux)
Print the size of linux and all its direct dependencies.
${1##*/} -Qst \$(pacman -Qdtq)
$ ${1##*/} -st \$(pacman -Qdtq)
Print a grand total of orphan packages, and sort by size.
EOF
}
db="Q"
version () {
echo "$myname $myver"
echo 'Copyright (C) 2014 Pierre Neidhardt <ambrevar@gmail.com>'
}
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 "=[ \t]*" '/^[ \t]*DBPath[ \t]*=/{gsub(/[ \t]*$/, "", $2); print $2}' /etc/pacman.conf 2>/dev/null)"
[ -z "$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)
}
/^%SIZE%/ {
getline
size = $0 / 1024
printf ("%6s KiB %s\n", size, pkg)
}' "$DBPath"/local/*/desc | ($opt_sort || cat) | ($opt_total || cat)
exit
$0 == "%NAME%" {
getline pkg
}
$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 ;}
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
## Remove this check if integrated to pacman.
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:

View File

@ -1,25 +0,0 @@
#!/bin/sh
rawname=${0##*/}
rawname=${rawname#p}
if [ "$1" = "-h" ]; then
cat <<EOF
Usage: ${0##*/}
Run `sessionclean' if available and $rawname the system.
EOF
exit
fi
command -v sessionclean >/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

View File

@ -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