summarylogtreecommitdiffstats
diff options
context:
space:
mode:
authorMoritz Lüdecke2015-06-08 15:42:33 +0200
committerMoritz Lüdecke2015-06-08 15:42:33 +0200
commit4f9c4a1104e5f6968c5be31c4b67e08dc5c0ed20 (patch)
tree319929870cd6b60236a502b9cea994824748dbf9
downloadaur-4f9c4a1104e5f6968c5be31c4b67e08dc5c0ed20.tar.gz
Initial import
-rw-r--r--.SRCINFO15
-rw-r--r--PKGBUILD24
-rwxr-xr-xpbar229
3 files changed, 268 insertions, 0 deletions
diff --git a/.SRCINFO b/.SRCINFO
new file mode 100644
index 000000000000..10adfa091cfb
--- /dev/null
+++ b/.SRCINFO
@@ -0,0 +1,15 @@
+pkgbase = pbar
+ pkgdesc = Progress bar in pacman style
+ pkgver = 20150414
+ pkgrel = 1
+ url = https://github.com/ritze/pbar
+ arch = any
+ license = GPL
+ makedepends = git
+ depends = bash
+ conflicts = pbar
+ source = pbar::git+https://github.com/ritze/pbar.git#branch=master
+ md5sums = SKIP
+
+pkgname = pbar
+
diff --git a/PKGBUILD b/PKGBUILD
new file mode 100644
index 000000000000..b7b7e592f79e
--- /dev/null
+++ b/PKGBUILD
@@ -0,0 +1,24 @@
+# Maintainer: Moritz Luedecke <ritze@skweez.net>
+# Contributor: Gilrain <pierre.buard+aur gmail com>
+# Contributor: bruenig
+pkgname=pbar
+pkgver=20150414
+pkgrel=1
+pkgdesc="Progress bar in pacman style"
+url="https://github.com/ritze/pbar"
+license="GPL"
+arch=('any')
+makedepends=('git')
+depends=('bash')
+conflicts=('pbar')
+source=("${pkgname}::git+https://github.com/ritze/pbar.git#branch=master")
+md5sums=('SKIP')
+
+pkgver() {
+ cd "$pkgname"
+ git show -s --format="%ci" HEAD | sed -e 's/-//g' -e 's/ .*//'
+}
+
+package() {
+ install -Dm755 "$srcdir/$pkgname/pbar" "$pkgdir/usr/bin/pbar"
+}
diff --git a/pbar b/pbar
new file mode 100755
index 000000000000..1b25005ccbfd
--- /dev/null
+++ b/pbar
@@ -0,0 +1,229 @@
+#!/bin/bash
+# Copyright Matthew Bruenig <matthewbruenig@gmail.com> (packer)
+# Moritz Lüdecke <ritze@skweez.net>
+# 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, either version 3 of the License, or
+# (at your option) any later version.
+
+# 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/>.
+
+DASH="-"
+HASH="#"
+BEGINBAR="["
+ENDBAR="]"
+INFBAR_UPDATE="0.1"
+
+usage() {
+ echo 'usage: pbar [OPTION] [-t DEVICE] DONE TOTAL [TITLE] [DETAILS]...'
+ echo
+ echo ' -i infinite progressbar,'
+ echo ' -n outputs a new line at the end'
+ echo ' -t set the tty device'
+ echo ' -h display this help and exit'
+ echo
+ echo 'Examples:'
+ echo ' pbar -n 3 5 "testing..." 3 of 5 Print the follow line:'
+ echo 'testing... 3 of 5 [##########--------] 60%'
+ echo ' pbar -i 0 0 "testing..." Print a infinite working progressbar:'
+ echo 'testing... [------###---------]'
+ exit
+}
+
+screenwidth() {
+ tty=$1
+ width="$(stty -F $tty size)"
+ echo "${width##* }"
+}
+
+removeformat() {
+ echo "$(expr "$1" | sed -r "s/\\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g")"
+}
+
+info() {
+ width=$1
+ title=$2
+ misc=$3
+
+ # Get vars for output
+ beginline=$title
+ misclen=0
+ # Remove color code
+ if [[ $misc != "" ]]; then
+ misctext=$(removeformat "$misc")
+ misclen=$((1+${#misctext}))
+ fi
+ beginlinetext=$(removeformat "$beginline")
+ if [[ $width -lt $((${#beginlinetext}+2+$misclen-1)) ]]; then
+ # Remove color code, cut the text and print it without color code
+ beginlinetext=${beginlinetext::$((width-$misclen-4))}
+ beginline=$beginlinetext"..."
+ beginlinetext=$(removeformat "$beginline")
+ fi
+ spaces="$(($width-${#beginlinetext}-1-$misclen))"
+
+ # Print output
+ printf "$beginline %${spaces}s"
+ [[ $misc != "" ]] && printf " $misc"
+}
+
+drawsymbol() {
+ symbol=$1
+ num=$2
+
+ for ((n=0; n<$num; n++)); do
+ printf "$symbol"
+ done
+}
+
+# This method is a fork from the packer method aurbar
+progbar() {
+ width=$1
+ infinite=$2
+ done=$3
+ total=$4
+
+ # Get vars for output
+ barchars="$(($width-${#BEGINBAR}-${#ENDBAR}-6))"
+ hashes="$(($barchars*$done/$total))"
+ dashes="$(($barchars-$hashes))"
+
+ # Print output
+ printf " ${BEGINBAR}"
+
+ if [[ $infinite ]]; then
+ offset="$(($hashes-2))"
+ hashes=3
+ [[ $offset -lt 0 ]] && offset=0 && hashes=2
+ drawsymbol $DASH $offset
+
+ offset="$(($offset+$hashes))"
+ [[ $offset -gt $barchars ]] && hashes=2
+ drawsymbol $HASH $hashes
+
+ dashes="$(($barchars-$offset))"
+ drawsymbol $DASH $dashes
+ printf "%s \r" ${ENDBAR}
+ else
+ drawsymbol $HASH $hashes
+ drawsymbol $DASH $dashes
+ perc="$(($done*100/$total))"
+ printf "%s%4s%%\r" ${ENDBAR} ${perc}
+ fi
+}
+
+printline() {
+ tty=$1
+ infinite=$2
+ done=$3
+ total=$4
+ title=$5
+ misc=$6
+
+ width=$(screenwidth $tty)
+ infolen="$(($width*6/10))"
+ [ $width -lt 50 ] && width=50
+ progbarlen="$(($width-$infolen))"
+
+ if [[ $total -eq 0 ]]; then
+ total=$(($progbarlen-9))
+
+ newdone="$(($done % $total))"
+ if [[ $(($done % $((2*$total)))) -ge $total ]]; then
+ newdone="$(($total-$newdone))"
+ fi
+ done=$(($newdone+1))
+ total=$(($total+1))
+ fi
+
+ # Delete line
+ printf "\033[0G"
+
+ info $infolen "$title" "$misc"
+ progbar $progbarlen "$infinite" $done $total
+}
+
+# Argument parsing
+
+[[ $1 ]] || usage
+
+while getopts ":hint:" optname; do
+ case "$optname" in
+ "i")
+ infinite=1
+ ;;
+ "n")
+ newline=1
+ ;;
+ "t")
+ tty=$OPTARG
+ ;;
+ "h")
+ usage
+ ;;
+ "?")
+ echo "Unknown option $OPTARG"
+ usage
+ ;;
+ ":")
+ echo "No argument value for option $OPTARG"
+ ;;
+ *)
+ echo "Unknown error while processing options"
+ ;;
+ esac
+done
+
+done=${@:$OPTIND:1}
+total=${@:$OPTIND+1:1}
+title="${@:$OPTIND+2:1}"
+misc="${@:$OPTIND+3}"
+
+int='^[0-9]+$'
+
+if [[ $tty == "" ]]; then
+ tty=$(tty)
+ if [[ $? -ne 0 ]]; then
+ echo "Can't get tty device!"
+ usage
+ fi
+fi
+
+if [[ $total -eq "" ]] ||
+ ! [[ $done =~ $int ]] || ! [[ $total =~ $int ]]; then
+
+ if [[ $done -ne 0 ]] || [[ $total -ne 0 ]] || [[ $infinite -ne 1 ]]; then
+ usage
+ fi
+fi
+
+if [[ $done -gt $total ]]; then
+ done=$total
+fi
+
+if [[ $done -eq 0 ]] && [[ $total -eq 0 ]] && [[ $infinite -eq 1 ]]; then
+ trap "exit=true" SIGINT SIGTERM
+ i=0
+ while [ ! $exit ]; do
+ printline $tty "$infinite" $i 0 "$title" "$misc"
+ i="$(($i+1))"
+ sleep $INFBAR_UPDATE
+ done
+
+ # Delete line
+ printf "\033[0G"
+
+ [ $newline ] && printline $tty "" 1 1 "$title" "$misc"
+else
+ printline $tty "$infinite" $done $total "$title" "$misc"
+fi
+
+[ $newline ] && echo
+
+exit