diff options
author | tdro <tdro@users.noreply.github.com> | 2019-04-16 02:28:43 -0400 |
---|---|---|
committer | tdro <tdro@users.noreply.github.com> | 2019-04-16 02:28:43 -0400 |
commit | 96ec7bad30b94d5a5e41a55ad876e94d7fe1e827 (patch) | |
tree | de44ce855361621871eb900e870c2823f6222f24 /.config/ranger | |
parent | b5253aa1b39974f1924db0debd4dbb37c80255e0 (diff) | |
download | dotfiles-96ec7bad30b94d5a5e41a55ad876e94d7fe1e827.tar.gz dotfiles-96ec7bad30b94d5a5e41a55ad876e94d7fe1e827.tar.bz2 dotfiles-96ec7bad30b94d5a5e41a55ad876e94d7fe1e827.zip |
dotfiles: Add ranger configs
Diffstat (limited to '.config/ranger')
-rw-r--r-- | .config/ranger/rc.conf | 38 | ||||
-rw-r--r-- | .config/ranger/scripts/imgtools | 218 | ||||
-rw-r--r-- | .config/ranger/scripts/pdftools | 159 | ||||
-rw-r--r-- | .config/ranger/scripts/rntools | 231 |
4 files changed, 646 insertions, 0 deletions
diff --git a/.config/ranger/rc.conf b/.config/ranger/rc.conf new file mode 100644 index 0000000..73e3b88 --- /dev/null +++ b/.config/ranger/rc.conf @@ -0,0 +1,38 @@ +# Enable image previews (urxvt compiled with pixbuf support needed) +set preview_images true +set preview_images_method urxvt + + +# Open terminal in current directory +map e. shell urxvt & + +# Image tools +map ei shell bash ~/.config/ranger/scripts/imgtools '%s' + +# Pdf Tools +map ep shell bash ~/.config/ranger/scripts/pdftools '%s' + +# Raname Tools +map er shell bash ~/.config/ranger/scripts/rntools %s + +# Compare with meld +map ec shell meld %s & + +# Sublime text +map es shell subl3 %s & + +# Fuzzy file search +map ef shell fzf + +# Current directory file usage +map eu shell ncdu -x . + +# Go to Trash Directory +map et cd ~/.local/share/Trash/files + + +# Move files to trash +map dd shell bash -c "touch %s; mv -t ~/.local/share/Trash/files %s" + +# Delete files older than 60 days in trash +map dD shell find ~/.local/share/Trash/files -mtime +60 -delete diff --git a/.config/ranger/scripts/imgtools b/.config/ranger/scripts/imgtools new file mode 100644 index 0000000..b281f7b --- /dev/null +++ b/.config/ranger/scripts/imgtools @@ -0,0 +1,218 @@ +#!/bin/bash +: <<COMMENT + Copyright (C) 2012 Tri Le <trile7 at gmail dot com> + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation version 3. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +COMMENT + +version="imgtools v0.1.1" +blue='\e[0;34m'; green='\e[0;32m'; red='\e[0;31m'; yellow='\e[0;33m'; bold='\e[1m'; none='\e[0m' +function menu { + n=0 + choices=("$@") + echo -e "$blue$bold$menutitle" + for i in "${choices[@]}"; do + echo -e "$none$((n++))) $yellow$i" + done + echo -en "${none}c|q) ${yellow}Cancel" + echo -e "$green" + read -rp "Enter a choice from above menu: " i + echo -e "$none" + [[ $i =~ c|q ]] && exit 1 + if test "$i" -lt $n 2>/dev/null; then + choice=${choices[i]}; return "$i" + else + echo -e "$red$i is an invalid entry...please try again!" + menu "${choices[@]}" + fi + } + +function slideshow { + if [[ ${files[0]} = -* ]]; then + for i in 0 2 4; do + if [[ ${files[i]} = -* ]]; then opt=("${opt[@]}" "${files[i]}" "${files[i+1]}"); unset "files[i]" "files[i+1]"; fi + done + else + echo "Default delay 2 seconds, loop forever, and resize only large image to 800x600:" + echo " -delay 2 -loop 0 -resize 800x600>" + echo -ne "$green" + read -rp "Enter slideshow options (enter to use defaults): " -a opt + echo -ne "$none" + fi + for i in 0 2 4; do + case ${opt[i]} in + *delay) d=${opt[i+1]} ;; + *loop) l=${opt[i+1]} ;; + *resize) s=${opt[i+1]} ;; + esac + done + [[ ${files[2]} ]] || err "You must specify at least one image file" + display -coalesce -auto-orient -immutable -delay "${d:=2}" -loop "${l:=0}" -resize "${s:=800x600>}" "${files[@]}" + } + +function info { + echo -e "${yellow}image, format, dimension, geometry, depth, class, size, processing times $none" + for i in "${files[@]}"; do + [[ -f $i ]] && identify "$i" || echo -e "$red$i doesn't exist$none" + done + } + +function wallpaper { + if [[ ${files[0]} = -* ]]; then + choice=${files[0]//-}; img0=${files[1]} + else + img0=${files[0]} + menutitle="---Wallpaper Modes---" + menu "Tile" "Resize and Tile" "Center" "Resize and Center" "Stretch" + fi + [[ -f $img0 ]] || err "$img0 doesn't exist" + res=($(xrandr | grep \* | grep -o "[0-9]*x[0-9]*")) || res=($(xdpyinfo | grep dimensions: | grep -o "[0-9]*x[0-9]*")) || res=$(xprop -root _NET_DESKTOP_GEOMETRY | cut -d'=' -f2 | tr -d ' ' | tr ',' 'x') + rootsize=${res:=800x600}; rootw=${res%x*}; rooth=${res#*x} + img=/tmp/.wallpaper.jpg + case $choice in + [tT]ile) display -window root "$img0"; exit ;; + *[rR]esize*) convert "$img0" -resize $rootsize "$img" ;; + [sS]tretch) convert "$img0" -resize $rootsize! "$img" ;; + *) convert "$img0" -resize $rootsize\> "$img" ;; + esac + if [[ $choice = *[cC]enter* ]]; then + imgw=$(identify -format "%w" $img) + imgh=$(identify -format "%h" $img) + x=$((rootw-imgw)); x=$((x/2)) + y=$((rooth-imgh)); y=$((y/2)) + display -geometry $rootsize+$x+$y -window root $img + else + display -window root $img + fi + } + +function resize { + if [[ ${files[0]} = -*size ]]; then + s=${files[1]}; unset "files[0]" "files[1]" + else + echo -e "Use resize operators ${green}> < !${none} to determine what image size to resize. Examples:" + echo -e " ${green}800x600>${none} reduce only larger image to given size keeping aspect ratio" + echo -e " ${green}800x600<${none} enlarge only smaller image to given size keeping aspect ratio" + echo -e " ${green}800x600!${none} force image to given size ignoring aspect ratio" + echo -e " ${green}800x600${none} resize to given size keeping aspect ratio" + echo -ne "$green" + read -rp "Enter new size (WxH in pixel): " s + echo -e "$none" + fi + if [[ $s = [0-9]*[0-9] || $s = x[0-9]* || $s = [0-9]*x || $s = [0-9]*[\>\<\!] ]]; then + for i in "${files[@]}"; do + newname=${i%.*}_s$s.${i##*.} + [[ -f $i ]] && convert "$i" -resize "$s" "$newname" || echo -e "$red$i doesn't exit$none" + done + else + echo -e "${red}Invalid size$none" + resize "${files[@]}" + fi + } + +function rotate { + if [[ ${files[0]} = -*angle ]]; then + d=${files[1]}; unset "files[0]" "files[1]" + else + echo -ne "$green" + read -rp "Enter angle (non-zero number): " d + echo -ne "$none" + fi + if [[ $d -gt 0 || $d -lt 0 ]]; then + for i in "${files[@]}"; do + newname=${i%.*}_r$d.${i##*.} + [[ -f $i ]] && convert "$i" -rotate "$d" "$newname" || echo -e "$red$i doesn't exit$none" + done + else + echo -e "${red}Angle must be a non-zero number$none" + rotate "${files[@]}" + fi + } + +function format { + if [[ ${files[0]} = -* ]]; then + choice=${files[0]//-}; unset "files[0]" + else + menutitle="---Image Formats---" + menu "jpg" "png" "gif" "ico" "bmp" "tif" "ps" "pdf" + fi + for i in "${files[@]}"; do + newname=${i%.*}.$choice + if [[ ! -f $i ]]; then echo -e "$red$i doesn't exist$none"; continue; fi + if [[ $i = "$newname" ]]; then echo -e "$yellow$i is already $choice format$none"; continue; fi + case $choice in + tif|ps|pdf) convert "$i" -compress Zip "$newname" ;; + bmp) convert "$i" BMP3:"$newname" ;; + *) convert "$i" "$newname" ;; + esac + done + } + +function 2pdf { + if [[ ${files[0]} = -*name ]]; then + f=${files[1]}; unset "files[0]" "files[1]" + else + echo -e "${green}Default is combined_images.pdf" + read -rp "Enter pdf filename: " f + echo -ne "$none" + fi + if [[ -z $f ]]; then f=combined_images.pdf + elif [[ $f != *.pdf ]]; then f=$f.pdf; fi + [[ -e $f ]] && f=${f%.*}_$(date +%s).pdf + [[ ${files[2]} ]] || err "You must specify at least one image file" + mkdir -p "$(dirname "$f")" + convert "${files[@]}" -compress Zip "$f" + } + +function usage { + echo "$version" + echo -e "${bold}Usage: ${0##*/} [command] [option] images$none" + echo "Commands and options:" + echo " --slideshow [--delay sec --loop n --resize pixel]" + echo " --info" + echo " --wallpaper [--tile|--resizetile|--center|--resizecenter|--stretch]" + echo " --resize [--size pixel]" + echo " --rotate [--angle degree]" + echo " --format [--jpg|--png|--gif|--ico|--bmp|--tif|--ps|--pdf]" + echo " --2pdf [--name filename]" + exit + } + +function mainmenu { + if [[ $cmd ]]; then $cmd; return; fi + echo -e "${yellow}Files in selection:$none" + for i in "${files[@]}"; do echo -n "$i "; done + echo + menutitle="---Image Tools---" + menu "Image Slideshow" "Image Information" "Set Image as Wallpaper" "Image Resize" "Image Rotation" "Image Format Conversion" "Combine Images to PDF" + case $choice in + *Slideshow) slideshow ;; + *Info*) info ;; + *Wallpaper) wallpaper ;; + *Resize) resize ;; + *Rotation) rotate ;; + *Format*) format ;; + *PDF) 2pdf ;; + esac + mainmenu + } + +function err { echo -e "$red$*$none"; exit 1; } + +case $1 in + -h|--help) usage ;; + --*) cmd=${1//-}; shift; files=("$@") ;; + *) files=("$@") ;; +esac +[[ $# -eq 0 ]] && usage +mainmenu "$cmd" diff --git a/.config/ranger/scripts/pdftools b/.config/ranger/scripts/pdftools new file mode 100644 index 0000000..1aab379 --- /dev/null +++ b/.config/ranger/scripts/pdftools @@ -0,0 +1,159 @@ +#!/bin/bash +: <<COMMENT + Copyright (C) 2014 Tri Le <trile7 at gmail dot com> + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation version 3. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +COMMENT + +version="pdftools v0.2.3" +blue='\e[0;34m'; green='\e[0;32m'; red='\e[0;31m'; yellow='\e[0;33m'; bold='\e[1m';none='\e[0m' + +function menu { + n=0 + choices=("$@") + echo -e "$blue$bold$menutitle" + for i in "${choices[@]}"; do + echo -e "$none$((n++))) $yellow$i" + done + echo -en "${none}c|q) ${yellow}Cancel" + echo -e $green + read -p "Enter a choice from above menu: " i + echo -e $none + [[ $i =~ c|q ]] && exit 1 + if test $i -lt $n 2>/dev/null; then + choice=${choices[i]}; return $i + else + echo -e "$red$i is an invalid entry...please try again!" + menu "${choices[@]}" + fi +} + +function mainmenu { + if [[ -z $1 ]]; then + menutitle="---PDF Tools---" + menu "PDF Merge" "PDF Split" "PDF Extract" "PDF to JPG" "PDF to Text" + case $? in + 0) merge ;; + 1) split ;; + 2) extract ;; + 3) 2jpg ;; + 4) 2txt ;; + esac + else + $cmd + fi + mainmenu +} + +function merge { + if [[ ${#files[@]} -lt 2 ]]; then + echo -e "${red}Select at least 2 or more PDF files to merge" + exit 1 + fi + echo -ne $green + read -p "Enter merged pdf name (default merged.pdf): " f + echo -e $none + if [[ $f ]]; then + [[ $f != *.pdf ]] && f=$f.pdf + else f=merged.pdf + fi + [[ -e $f ]] && f=${f%.*}-`date +%s`.pdf + mkdir -p `dirname "$f"` + gs -o -q -sDEVICE=pdfwrite -sOutputFile="$f" "${files[@]}" + if [[ $? -eq 0 ]]; then + echo -e $green + read -p "Remove `echo ${files[@]}` (Y/n)? " i + [[ $i = n ]] || rm "${files[@]}" + fi +} + +function split { + for i in "${files[@]}"; do + totalp=`gs -q -dNODISPLAY -c "($i) (r) file runpdfbegin pdfpagecount = quit"` + for (( p=1; p<=$totalp; p++ )); do + gs -o -q -sDEVICE=pdfwrite -dFirstPage=$p -dLastPage=$p -sOutputFile="${i%.*}-p$p.pdf" "$i" + done + done +} + +function extract { + echo -e "Use ${green}space$none for separating pages, ${green}dash$none for range of pages, and ${green}end$none for the last page. For example, to extract pages 1, 5, and 8 to the last page, enter: ${green}1 5 8-end" + read -p "Enter page: " -a p + echo -e $none + if [[ -z $p ]]; then + echo -e "${red}A value is required for page $none" + extract "$@"; return 1 + fi + for i in ${p[@]}; do + [[ $i = end ]] && continue + test ${i%*-end} -gt 0 2>/dev/null && continue + test $((i)) -lt 0 2>/dev/null && continue + echo -e "${red}$i is invalid $none" + extract "$@"; return 1 + done + tmpdir=/tmp/pdfextract + mkdir -p $tmpdir + for i in "${files[@]}"; do + pages=`gs -q -dNODISPLAY -c "($i) (r) file runpdfbegin pdfpagecount = quit"` + for j in ${p[@]}; do + if [[ $j = *-* ]]; then + p1=`echo $j | cut -d'-' -f1` + [[ $p1 -gt $pages ]] && continue + p2=`echo $j | cut -d'-' -f2` + [[ $p2 = end ]] && p2=$pages + [[ $p2 -gt $pages ]] && p2=$pages + elif [[ $j = end ]]; then + p1=$pages; p2=$pages + elif [[ $j -le $pages ]]; then + p1=$j; p2=$j + fi + gs -o -q -sDEVICE=pdfwrite -dFirstPage=$p1 -dLastPage=$p2 -sOutputFile=$tmpdir/$j.pdf "$i" + done + ext=${p[@]} + ext=p${ext// /,}.pdf + gs -o -q -sDEVICE=pdfwrite -sOutputFile="${i%.*}-$ext" $tmpdir/*.pdf + rm -rf $tmpdir + done +} + +function 2jpg { + for i in "${files[@]}"; do + gs -o -q -sDEVICE=jpeg -sOutputFile="${i%.*}-p%d.jpg" "$i" + done +} + +function 2txt { + for i in "${files[@]}"; do + gs -o -q -sDEVICE=txtwrite -sOutputFile="${i%.*}.txt" "$i" + done +} + +function usage { + echo -e "${bold}$version" + echo -e "Usage: ${0##*/} [option] pdf1 pdf2 ..... $none" + echo "Options: menu is shown if option is not specified" + echo " --merge combine 2 or more pdf files to one" + echo " --split split pdf file to individual page" + echo " --extract extract page and/or range of pages from pdf file" + echo " --2jpg convert pdf page to jpg" + echo " --2txt convert text portion of pdf file to text" + exit +} + +case $1 in + -h|--h*) usage ;; + --*) cmd=${1#--}; shift; files=("$@") ;; + *) files=("$@") ;; +esac +[[ $# -eq 0 ]] && usage +mainmenu $cmd
\ No newline at end of file diff --git a/.config/ranger/scripts/rntools b/.config/ranger/scripts/rntools new file mode 100644 index 0000000..76afdb8 --- /dev/null +++ b/.config/ranger/scripts/rntools @@ -0,0 +1,231 @@ +#!/bin/bash +: <<COMMENT + Copyright (C) 2012 Tri Le <trile7 at gmail dot com> + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation version 3. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +COMMENT + +version="rename v0.3" +blue='\e[0;34m'; green='\e[0;32m'; red='\e[0;31m'; yellow='\e[0;33m'; bold='\e[1m';none='\e[0m' + +function menu { + n=0 + choices=("$@") + echo -e "$blue$bold$menutitle" + for i in "${choices[@]}"; do + echo -e "$none$((n++))) $yellow$i" + done + echo -en "${none}c|q) ${yellow}Cancel" + echo -e $green + read -p "Enter a choice from above menu: " i + echo -e $none + [[ $i =~ c|q ]] && exit 1 + if test $i -lt $n 2>/dev/null; then + choice=${choices[i]}; return $i + else + echo -e "$red$i is an invalid entry...please try again!" + menu "${choices[@]}" + fi + } + +function space2_ { + newname=${1// /_} + } + +function _2space { + newname=${1//_/ } + } + +function upper { + newname=`echo $1 | tr [:lower:] [:upper:]` + } + +function lower { + newname=`echo $1 | tr [:upper:] [:lower:]` + } + +function upperfirst { + words=(`echo "$1"`) + W="" + for w in ${words[@]}; do + x=`echo ${w:0:1}` + X=`echo ${w:0:1} | tr [:lower:] [:upper:]` + W=($W ${w/$x/$X}) + done + newname=`echo ${W[@]}` + } + +function x2y { + echo -ne $none + if [[ -z $x ]]; then + echo -e "Use wildcard ${green}?${none} to match any one character or ${green}*${none} to match all characters" + echo -ne $green + read -p "Enter x (find value, required): " x + if [[ -z $x ]]; then + err "x is required" + x2y; return 1 + fi + fi + [[ $j ]] || read -p "Enter y (replacement value; leave blank to remove x): " y + j=1 + newname=${1//$x/$y} + } + +function insert { + echo -ne $none + if [[ -z $p ]]; then + echo -e "Use ${green}0${none} for the beginning of name, ${green}end${none} for the end of name, or ${green}end-ext${none} for the end of name but keep extension." + echo -ne $green + read -p "Enter p (insert position, required): " p + if ! test $p -ge 0 2>/dev/null && [[ $p != end* ]]; then + err "$p is invalid" + p=""; insert + fi + fi + if [[ -z $x && $p ]]; then + echo -e "${none}Use ${green}%${none} for counter." + echo -ne $green + read -p "Enter x (character to insert, required): " x + if [[ -z $x ]]; then + err "x is required" + x=""; insert + fi + fi + if [[ $x = *%* && -z $c && $p ]]; then + echo -e "${none}Start counter (include number of digits; i.e. 3 digits counter starting at 1, enter: 001)" + echo -ne $green + read -p "Enter start counter n (n >= 0, required): " c + if ! test $c -ge 0 2>/dev/null; then + err "$c is invalid" + c=""; insert + fi + n=`expr $c + ${#files[@]} - 1` + c=(`seq -w $c 1 $n`) + fi + case $p in + end) pos=${#1} ;; + end-ext) noext=${1%.*}; pos=${#noext} ;; + *) pos=$p ;; + esac + if [[ $c ]]; then + counter=${c[$j]} + x1=${x//%/$counter} + newname=${1:0:$pos}$x1${1:$pos} + else + newname=${1:0:$pos}$x${1:$pos} + fi + } + +function remove { + echo -ne $none + if [[ -z $p ]]; then + echo -e "Use ${green}0${none} for the beginning of name" + echo -ne $green + read -p "Enter p (remove position, p >= 0, required): " p + if ! test $p -ge 0 2>/dev/null; then + err "$p is invalid" + p=""; remove + fi + fi + [[ $p ]] && read -p "Enter n (number of characters to remove): " n + [[ $p -eq 0 ]] && x1="" || x1=${1:0:p} + p2=$((p+n)) + x2=${1:p2} + newname=$x1$x2 + } + +function err { + echo -e "$red$@$none"; echo; return 1 + } + +function changename { + if $cmd; then + echo -e $none + echo -e "${bold}Changes preview:" + j=0 + for i in "${files[@]}"; do + $cmd "$i" || continue + [[ $newname ]] || newname="${red}SKIPPED" + ((j++)) + echo -e "$yellow$i -> $bold$newname" + done + echo -e $green + read -p "Do you want to proceed with rename (Y/n)? " ans + echo -e $none + if [[ $ans = n ]]; then + unset p x c; mainmenu + else + j=0 + for i in "${files[@]}"; do + [[ -e $i ]] || continue + $cmd "$i" || continue + [[ $newname ]] || continue + ((j++)) + if [[ -d $i ]] && [[ $cmd = upper* || $cmd = lower ]]; then + mv "$i" "$newname$$" + mv "$newname$$" "$newname" + else + mv "$i" "$newname" + fi + done + fi + else + mainmenu + fi + } + +function mainmenu { + if [[ -z $1 ]]; then + echo "-------------------" + echo -e "${bold}Files to be renamed:" + echo -ne $yellow + for i in "${files[@]}"; do echo $i; done + echo -e $none + menutitle="---Rename Tools---" + menu "Space_to_underscore" "Underscore to space" "ALL UPPERCASE" "all lowercase" "Uppercase First Letter of Each Word" "Convert x to y" "Insert counter n and/or character x at position p" "Remove n number of characters at position p" + case $? in + 0) cmd=space2_ ;; + 1) cmd=_2space ;; + 2) cmd=upper ;; + 3) cmd=lower ;; + 4) cmd=upperfirst ;; + 5) cmd=x2y ;; + 6) cmd=insert ;; + 7) cmd=remove ;; + esac + fi + changename + } + +function usage { + echo -e "${bold}$version" + echo -e "Usage: ${0##*/} [options] filename1 filename2 ..... $none" + echo "Options: menu is shown if option is not specified" + echo " --space2_ convert_space_to_underscore" + echo " --_2space convert underscore to space" + echo " --upper CONVERT ALL TO UPPERCASE" + echo " --lower convert all to lowercase" + echo " --upperfirst Convert First Letter Of A Word To Uppercase" + echo " --x2y Convert x to y" + echo " --insert Insert counter or characters at a specific position" + echo " --remove Remove numbers of characters at a specific position" + exit + } + +case $1 in + -h|--h*) usage ;; + --*) cmd=${1#--}; shift; files=("$@") ;; + *) files=("$@") ;; +esac +[[ $# -eq 0 ]] && usage +mainmenu $cmd
\ No newline at end of file |