elvish_config/aliases/pdf2grey.elv

83 lines
1.8 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

edit:add-var pdf2grey~ {|@argv|
use re
use str
var m = [
&nb=$false
&split=50
]
fn _help {||
echo 'Usage: pdf2gray [-hn (<n>)] <input>.pdf <output>.pdf'
echo ''
echo 'Options:'
echo ' -h Affiche cette aide'
echo ' -n [0-100] Convertit en noir et blanc. Si un nombre est spécifié, indique le pourcentage de coupure (par défaut: 50)'
}
fn is_pdf {|e|
re:match '.*\.pdf$' $e
}
fn is_int {|e|
re:match '^\d+$' $e
}
fn is_split {|e|
and (>= $e 0) (<= $e 100)
}
while (> (count $argv) 0) {
var e @argv = $@argv
if (or (eq $e '-h') (eq $e '--help')) {
_help
return
} elif (eq $e -n) {
set m[nb] = $true
if (== (count $e) 0) {
echo 'Il manque des arguments après -s'
_help
return
} elif (is_int $argv[0]) {
set e @argv = $@argv
if (is_split $e) {
set m[split] = $e
} else {
echo 'Largument (optionnel) après -s doit être compris entre 0 et 100'
_help
return
}
}
} elif (not (is_pdf $e)) {
echo 'Argument non reconnu: '$e
_help
return
} elif (not (has-key $m input)) {
set m[input] = $e
} else {
set m[output] = $e
if (> (count $argv) 0) {
echo 'Trop darguments: '$@argv
_help
return
}
}
}
if (not (has-key $m input)) {
echo 'Manque le input'
_help
return
} elif (not (has-key $m output)) {
echo 'Manque le output'
_help
return
}
var params = [-colorspace gray]
if $m[nb] {
set @params = (all $params) -threshold $m[split]'%'
}
set @params = $@params $m[input] $m[output]
echo 'Commande: convert '(str:join ' ' $params)
convert $@params
}