From d8ed68edcb4dddde9f8b731977c023ac75991463 Mon Sep 17 00:00:00 2001 From: levasseur Date: Wed, 22 Sep 2021 17:11:42 +0200 Subject: [PATCH] fixed profile tabs --- repo/common/profile | 947 ++++++++++++++++++++++---------------------- 1 file changed, 477 insertions(+), 470 deletions(-) diff --git a/repo/common/profile b/repo/common/profile index 14871a9..be68da7 100644 --- a/repo/common/profile +++ b/repo/common/profile @@ -1,23 +1,23 @@ #!/bin/bash # Begin profile -# ------------------------------------------------------------------------------------------ +# ------------------------------------------------------------------------------ # Initial version from Beyond Linux From Scratch by # * James Robertson # * Dagmar d'Surreal -# ------------------------------------------------------------------------------------------ +# ------------------------------------------------------------------------------ # Current version from Geoffray Levasseur # 16/02/2013 Version 1.0.0 : Initial version -# 24/10/2015 Version 2.0.0 : Added some advanced functionnalities (clean, srr, etc.) +# 24/10/2015 Version 2.0.0 : Added advanced functionnalities (clean, srr, etc.) # 04/02/2017 Version 2.0.1 : clean improvements (--shell) -# 16/09/2018 Version 2.1.0 : Added rmhost, setc, setfr, review of locales management +# 16/09/2018 Version 2.1.0 : Added rmhost, setc, setfr, more locales management # 23/09/2019 Version 2.1.1 : [bugfix] dpkgs # 24/09/2019 Version 2.1.2 : [bugfix] bug in profile version display -# 16/12/2019 Version 2.2.0 : Added showinfo, primary write of showdiskmap (to be finished) -# 08/01/2020 Version 2.3.0 : Added use of figlet and neofetch as an equivalent to motd -# 16/01/2020 Version 2.3.1 : [bugfix] non-interactive mode were blocked with some functions -# 31/01/2020 Version 2.3.2 : Figlet : changed default font to ansi_shadow +# 16/12/2019 Version 2.2.0 : Added showinfo, primary write of showdiskmap +# 08/01/2020 Version 2.3.0 : Added use of figlet and neofetch as a motd replace +# 16/01/2020 Version 2.3.1 : [bugfix] non-interactive were blocked with some functions +# 31/01/2020 Version 2.3.2 : Figlet: changed default font to ansi_shadow # 02/03/2020 Version 2.4.0 : Added command auzip -# 03/03/2020 Version 2.5.0 : Added command taz and rmspc, auzip renamed utaz and improved +# 03/03/2020 Version 2.5.0 : Added command taz and rmspc, auzip->utaz improved # 05/03/2020 Version 2.5.1 : Language consistancy fix, added pigz support in taz # 06/03/2020 Version 2.5.2 : Few aliases sorted out # 11/09/2020 Version 2.5.3 : Few more aliases, improved code consistancy and typo, @@ -26,7 +26,7 @@ # 24/10/2020 Version 2.6.0 : Added session save and restore for Konsole # 25/12/2020 Version 2.6.1 : Add check on rmhost, improvements rmspc, created expendlist # 26/02/2021 Version 2.6.2 : taz: corrected bug with trailing slash on directories -# ------------------------------------------------------------------------------------------ +# ------------------------------------------------------------------------------ # Copyright (c) 2013-2020 Geoffray Levasseur # Protected by the BSD3 license. Please read bellow for details. # @@ -59,60 +59,60 @@ # * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, # * OF SUCH DAMAGE. -# ------------------------------------------------------------------------------------------ +# ------------------------------------------------------------------------------ -export PROFVERSION="2.6.1" +export PROFVERSION="2.6.2" export DEFAULT_CITY="Toulouse" -# ------------------------------------------------------------------------------------------ +# ------------------------------------------------------------------------------ # path* : private functions for PATH variable management -# ------------------------------------------------------------------------------------------ +# ------------------------------------------------------------------------------ pathremove () { - local ifs=':' - local newpath - local dir - local pathvar=${2:-PATH} - for dir in ${!pathvar} ; do - if [ "$dir" != "$1" ] ; then - newpath=${newpath:+$newpath:}$dir - fi - done - export $pathvar="$newpath" + local ifs=':' + local newpath + local dir + local pathvar=${2:-PATH} + for dir in ${!pathvar} ; do + if [ "$dir" != "$1" ] ; then + newpath=${newpath:+$newpath:}$dir + fi + done + export $pathvar="$newpath" } pathprepend () { - pathremove $1 $2 - local pathvar=${2:-PATH} - export $pathvar="$1${!pathvar:+:${!pathvar}}" + pathremove $1 $2 + local pathvar=${2:-PATH} + export $pathvar="$1${!pathvar:+:${!pathvar}}" } pathappend () { - pathremove $1 $2 - local pathvar=${2:-PATH} - export $pathvar="${!pathvar:+${!pathvar}:}$1" + pathremove $1 $2 + local pathvar=${2:-PATH} + export $pathvar="${!pathvar:+${!pathvar}:}$1" } -# ------------------------------------------------------------------------------------------ +# ------------------------------------------------------------------------------ # expandlist : treat wildcards in a file/directory list -# ------------------------------------------------------------------------------------------ +# ------------------------------------------------------------------------------ expandlist() { local result="" for item in "$1"; do - for content in "$item"; do - result+="\"$content\" " - done + for content in "$item"; do + result+="\"$content\" " + done done echo $result } -# ------------------------------------------------------------------------------------------ +# ------------------------------------------------------------------------------ # timer_* functions : internal timing function for prompt -# ------------------------------------------------------------------------------------------ +# ------------------------------------------------------------------------------ function timer_now { date +%s%N @@ -132,20 +132,27 @@ function timer_stop local m=$(((delta_us / 60000000) % 60)) local h=$((delta_us / 3600000000)) # Goal: always show around 3 digits of accuracy - if ((h > 0)); then timer_show=${h}h${m}m - elif ((m > 0)); then timer_show=${m}m${s}s - elif ((s >= 10)); then timer_show=${s}.$((ms / 100))s - elif ((s > 0)); then timer_show=${s}.$(printf %03d $ms)s - elif ((ms >= 100)); then timer_show=${ms}ms - elif ((ms > 0)); then timer_show=${ms}.$((us / 100))ms - else timer_show=${us}us + if ((h > 0)); then + timer_show=${h}h${m}m + elif ((m > 0)); then + timer_show=${m}m${s}s + elif ((s >= 10)); then + timer_show=${s}.$((ms / 100))s + elif ((s > 0)); then + timer_show=${s}.$(printf %03d $ms)s + elif ((ms >= 100)); then + timer_show=${ms}ms + elif ((ms > 0)); then + timer_show=${ms}.$((us / 100))ms + else + timer_show=${us}us fi unset timer_start } -# ------------------------------------------------------------------------------------------ +# ------------------------------------------------------------------------------ # Function triguered internaly by bash : defining prompt -# ------------------------------------------------------------------------------------------ +# ------------------------------------------------------------------------------ set_prompt () { Last_Command=$? # Must come first! @@ -170,11 +177,11 @@ set_prompt () # If it was successful, print a green check mark. Otherwise, print # a red X. if [[ $Last_Command == 0 ]]; then - PS1+="$White$OnBlue[ \$Last_Command " - PS1+="$Green$Checkmark " + PS1+="$White$OnBlue[ \$Last_Command " + PS1+="$Green$Checkmark " else - PS1+="$White$OnRed[ \$Last_Command " - PS1+="$Yellow$FancyX " + PS1+="$White$OnRed[ \$Last_Command " + PS1+="$Yellow$FancyX " fi # Add the ellapsed time and current date @@ -184,26 +191,27 @@ set_prompt () # If root, just print the host in red. Otherwise, print the current user # and host in green. if [[ $EUID -eq 0 ]]; then - PS1+="$Red\\u$Green@\\h " + PS1+="$Red\\u$Green@\\h " else - PS1+="$Green\\u@\\h " + PS1+="$Green\\u@\\h " fi # Print the working directory and prompt marker in blue, and reset # the text color to the default. PS1+="$ICyan\\w \\\$$Default " } -# ------------------------------------------------------------------------------------------ +# ------------------------------------------------------------------------------ # Show profile version -# ------------------------------------------------------------------------------------------ +# ------------------------------------------------------------------------------ ver () { echo "Profile version $PROFVERSION." } export ver -# ------------------------------------------------------------------------------------------ + +# ------------------------------------------------------------------------------ # Change locale to French -# ------------------------------------------------------------------------------------------ +# ------------------------------------------------------------------------------ setfr () { # Set fr locale definitions @@ -213,9 +221,9 @@ setfr () } export setfr -# ------------------------------------------------------------------------------------------ +# ------------------------------------------------------------------------------ # Change locale to C standard -# ------------------------------------------------------------------------------------------ +# ------------------------------------------------------------------------------ setc () { # Locale definitions @@ -225,9 +233,9 @@ setc () } export setc -# ------------------------------------------------------------------------------------------ +# ------------------------------------------------------------------------------ # Change locale to US (needed by Steam) -# ------------------------------------------------------------------------------------------ +# ------------------------------------------------------------------------------ setus () { # Locale definitions @@ -237,63 +245,63 @@ setus () } export setc -# ------------------------------------------------------------------------------------------ +# ------------------------------------------------------------------------------ # Display weather of the given city (or default one) -# ------------------------------------------------------------------------------------------ +# ------------------------------------------------------------------------------ meteo () { cities=$@ [[ $# -eq 0 ]] && local cities=$DEFAULT_CITY for city in $cities; do - curl wttr.in/$city + curl wttr.in/$city done } export meteo -# ------------------------------------------------------------------------------------------ +# ------------------------------------------------------------------------------ # Clean a directory or a tree from temporary or backup files -# ------------------------------------------------------------------------------------------ +# ------------------------------------------------------------------------------ clean () { for opt in $@ ; do - case $opt in - "-r"|"--recurs") - local recursive=1 - ;; + case $opt in + "-r"|"--recurs") + local recursive=1 + ;; - "-h"|"--help") - echo "clean : erase backup files in the given directories." - echo - echo "Usage : clean [option] [directory1] [...[directoryX]]" - echo - echo "Options :" - echo " -h, --help Display that help screen" - echo " -r, --recurs Do a recursive cleaning" - echo " -f, --force Do not ask for confirmation (use with care)" - echo " -s, --shell Do nothing and display what will be executed" - echo - return 0 - ;; + "-h"|"--help") + echo "clean: erase backup files in the given directories." + echo + echo "Usage: clean [option] [directory1] [...[directoryX]]" + echo + echo "Options:" + echo " -h, --help Display that help screen" + echo " -r, --recurs Do a recursive cleaning" + echo " -f, --force Do not ask for confirmation (use with care)" + echo " -s, --shell Do nothing and display what will be executed" + echo + return 0 + ;; "-s"|"--shell") - local outshell=1 - ;; + local outshell=1 + ;; - "-f"|"--force") - local force=1 - ;; + "-f"|"--force") + local force=1 + ;; - "-"*) - echo "Invalid option, use \"clean --help\" to display usage." - echo - return 1 - ;; + "-"*) + echo "Invalid option, use \"clean --help\" to display usage." + echo + return 1 + ;; - *) - local dirlist="$dirlist $opt" - ;; - esac + *) + local dirlist="$dirlist $opt" + ;; + esac done [[ ! $dirlist ]] && local dirlist=$(pwd) @@ -303,41 +311,42 @@ clean () unset recursive force for dir in $dirlist; do - local dellist=$(find $dir $findopt -type f -name "*~" -o -name "#*#" -o -name "*.bak" -o -name ".~*#") - for f in $dellist; do - if [[ ! $outshell ]]; then - rm $rmopt $f - else - echo "rm $rmopt $f" - fi - done + local dellist=$(find $dir $findopt -type f -name "*~" -o -name "#*#" \ + -o -name "*.bak" -o -name ".~*#") + for f in $dellist; do + if [[ ! $outshell ]]; then + rm $rmopt $f + else + echo "rm $rmopt $f" + fi + done done unset outshell dirlist dellist findopt rmopt } export clean -# ------------------------------------------------------------------------------------------ +# ------------------------------------------------------------------------------ # Login root via SSH on the given machine -# ------------------------------------------------------------------------------------------ +# ------------------------------------------------------------------------------ ssr () { for opt in $@ ; do - case $opt in - "-h"|"--help") - echo "ssr: do a root user ssh login." - echo - echo "Usage : ssr " - return 0 - ;; - esac + case $opt in + "-h"|"--help") + echo "ssr: do a root user ssh login." + echo + echo "Usage: ssr " + return 0 + ;; + esac done [[ ! $1 ]] && - echo "Please specify the server you want to log in." && return 1 + echo "Please specify the server you want to log in." && return 1 local srv=$1 && shift - ssh -x root@$srv $@ + ssh -y root@$srv $@ } export ssr @@ -348,28 +357,28 @@ dpkgs () { local count=0 for opt in $@ ; do - case $opt in - "-h"|"--help") - echo "dpkgs: look for an installed package by it's name." - echo - echo "Usage: dpkgs " - return 0 - ;; + case $opt in + "-h"|"--help") + echo "dpkgs: look for an installed package by it's name." + echo + echo "Usage: dpkgs " + return 0 + ;; - "-"*) - echo "Invalid option, use \"dpkgs --help\" to display usage." - echo - return 1 - ;; + "-"*) + echo "Invalid option, use \"dpkgs --help\" to display usage." + echo + return 1 + ;; - *) - local pkg=$1 && shift - count=$(( $count + 1 )) - [[ $count -gt 1 ]] && - echo "*** Error: Please specify a package name, without space, eventually partial." && return 1 + *) + local pkg=$1 && shift + count=$(( $count + 1 )) + [[ $count -gt 1 ]] && + echo "*** Error: Please specify a package name, without space, eventually partial." && return 1 - ;; - esac + ;; + esac done [[ $count -lt 1 ]] && echo "*** Error: Please specify a package name, without space, eventually partial." && return 1 @@ -393,8 +402,8 @@ export ppg # ------------------------------------------------------------------------------------------ mcd () { if [[ ! $# -eq 1 ]] ; then - echo "Create a directory then goes inside." - echo "Usage : mcd " + echo "Create a directory then goes inside." + echo "Usage: mcd " return 1 fi mkdir -pv $1 && cd $1 @@ -407,12 +416,12 @@ export mcd gpid () { [[ $# -eq 1 ]] && local single=1 for pid in $@; do - local result=$(ps -A | grep $pid | awk '{print $1}') - if [[ $single ]]; then - [[ $result ]] && echo "$result" - else - [[ $result ]] && echo "$pid: $result" - fi + local result=$(ps -A | grep $pid | awk '{print $1}') + if [[ $single ]]; then + [[ $result ]] && echo "$result" + else + [[ $result ]] && echo "$pid: $result" + fi done [[ $result ]] || return 1 } @@ -423,9 +432,9 @@ export gpid # ------------------------------------------------------------------------------------------ rmhost () { if [[ "$#" -ne 1 ]]; then - echo "Error: incorrect number of parameters." - echo "Usage: rmhost " - return 1 + echo "Error: incorrect number of parameters." + echo "Usage: rmhost " + return 1 fi hst=$1 @@ -445,67 +454,67 @@ export rmhost rmspc () { local lst="" for opt in $@ ; do - case $opt in - "-h"|"--help") - echo "rmspc : remove spaces from all filenames in current directories" - echo - echo "Usage : rmspc [option]" - echo - echo "Options :" - echo " -h, --help Display that help screen" - echo " -r, --recursive Treat subdiretories of the given directories" - echo " -c, --subst-char Change the replacement character (default is underscore)" - echo " -v, --verbose Display what is being done" - echo " -s, --shell Do nothing and display commands that would be executed" - echo - return 0 - ;; + case $opt in + "-h"|"--help") + echo "rmspc: remove spaces from all filenames in current directories" + echo + echo "Usage: rmspc [option]" + echo + echo "Options:" + echo " -h, --help Display that help screen" + echo " -r, --recursive Treat subdiretories of the given directories" + echo " -c, --subst-char Change the replacement character (default is underscore)" + echo " -v, --verbose Display what is being done" + echo " -s, --shell Do nothing and display commands that would be executed" + echo + return 0 + ;; - "-r"|"--recursive") - local recurs=1 - ;; + "-r"|"--recursive") + local recurs=1 + ;; - "-c"?*|"--subst-char"?*) - local substchar=$(echo "$opt" | cut -f 2- -d '=') - ;; + "-c"?*|"--subst-char"?*) + local substchar=$(echo "$opt" | cut -f 2- -d '=') + ;; - "-v"|"--verbose") - local verb=1 - ;; + "-v"|"--verbose") + local verb=1 + ;; - "-s"|"--shell") - local shell=1 - ;; + "-s"|"--shell") + local shell=1 + ;; - *) - echo "Invalid parameter, use \"rmspc --help\" to display options list" - echo - return 1 - ;; - esac + *) + echo "Invalid parameter, use \"rmspc --help\" to display options list" + echo + return 1 + ;; + esac done [[ ! $substchar ]] && substchar="_" [[ $verb ]] && local mvopt="-v" for f in *\ *; do - [[ $recurs ]] && [[ -d "$f" ]] && ( - #[[ $verb ]] && echo "Entering directory $f ..." - pushd "$f" > /dev/null - rmspc --subst-char="$substchar" $mvopt --shell - popd > /dev/null - #[[ $verb ]] && echo "Leaving directory $f" - ) - - if [[ $(echo $f | grep " ") ]]; then - local newf="${f// /${substchar}}" - local command="mv $mvopt \"$f\" \"$newf\"" - if [[ $shell ]]; then - echo $command - else - $command - fi - fi + [[ $recurs ]] && [[ -d "$f" ]] && ( + #[[ $verb ]] && echo "Entering directory $f ..." + pushd "$f" > /dev/null + rmspc --subst-char="$substchar" $mvopt --shell + popd > /dev/null + #[[ $verb ]] && echo "Leaving directory $f" + ) + + if [[ $(echo $f | grep " ") ]]; then + local newf="${f// /${substchar}}" + local command="mv $mvopt \"$f\" \"$newf\"" + if [[ $shell ]]; then + echo $command + else + $command + fi + fi done unset lst substchar verb shell newf command mvopt } @@ -517,45 +526,45 @@ export rmspc utaz() { for opt in $@ ; do - case $opt in - "-h"|"--help") - echo "utaz : uncompress all the given files and/or the ones found in the given" - echo " directories creating an host directory where needed." - echo - echo "Usage : utaz [option] [directorie(s)|file(s)]" - echo - echo "Options :" - echo " -h, --help Display that help screen" - echo " -d, --delete If decompression success, delete the source file" - echo " -c, --create-dir Always create a host directory" - echo " -n, --no-dir Never create a host directory" - echo - return 0 - ;; + case $opt in + "-h"|"--help") + echo "utaz: uncompress all the given files and/or the ones found in the given" + echo " directories creating an host directory where needed." + echo + echo "Usage: utaz [option] [directorie(s)|file(s)]" + echo + echo "Options:" + echo " -h, --help Display that help screen" + echo " -d, --delete If decompression success, delete the source file" + echo " -c, --create-dir Always create a host directory" + echo " -n, --no-dir Never create a host directory" + echo + return 0 + ;; - "-d"|"--delete") - local willrm=1 - ;; + "-d"|"--delete") + local willrm=1 + ;; - "-c"|"--create-dir") - local createdir=1 - ;; + "-c"|"--create-dir") + local createdir=1 + ;; - "-n"|"--no-dir") - local nodir=1 - ;; + "-n"|"--no-dir") + local nodir=1 + ;; - "-"*) - echo "Invalid option, use \"utaz --help\" to display options list" - echo - return 1 - ;; + "-"*) + echo "Invalid option, use \"utaz --help\" to display options list" + echo + return 1 + ;; - *) - # The ${opt%/} writing is to remove trailing / if any - local LIST="$LIST ${opt%/}" - ;; - esac + *) + # The ${opt%/} writing is to remove trailing / if any + local LIST="$LIST ${opt%/}" + ;; + esac done [[ $createdir && $nodir ]] && echo "*** Error: --create-dir and --no-dir options are mutually exclusive." @@ -563,51 +572,51 @@ utaz() [[ ! $LIST ]] && local LIST="." for zitem in $LIST; do - [[ $(ls $zitem/*.zip 2> /dev/null | wc -l) -eq 0 ]] && - echo "$zitem contains no supported archive file, skipping." && - continue + [[ $(ls $zitem/*.zip 2> /dev/null | wc -l) -eq 0 ]] && + echo "$zitem contains no supported archive file, skipping." && + continue - for f in $zitem/*.zip; do - echo -n "Processing archive $zitem/$f... " - local dir=${f::-4} - - mkdir -p $dir - [[ $? -gt 0 ]] && - echo "[ filesystem can't create directories, exit ]" && - return 1 + for f in $zitem/*.zip; do + echo -n "Processing archive $zitem/$f... " + local dir=${f::-4} - unzip -o $f -d $dir > /dev/null 2>&1 - case $? in - 0) - [[ $willrm ]] && rm -f $f && echo -n "Deleted ! " - ;; + mkdir -p $dir + [[ $? -gt 0 ]] && + echo "[ filesystem can't create directories, exit ]" && + return 1 - 1) - echo "No deletion on warnings " - ;; - *) - echo "[ zip file corrupted, failed ]" - rm -rf $dir > /dev/null 2>&1 - continue - ;; - esac + unzip -o $f -d $dir > /dev/null 2>&1 + case $? in + 0) + [[ $willrm ]] && rm -f $f && echo -n "Deleted ! " + ;; - if [[ $createdir ]]; then - echo -n "[ subdir created, " - elif [[ $nodir ]]; then - mv ./$dir/* ./ && rmdir $dir - echo -n "[ No subdir, " - else - subdirs=$(find $dir -maxdepth 1 | wc -l) - if [[ $subdirs -eq 2 ]]; then - mv ./$dir/* ./ && rmdir $dir - echo -n "[ No subdir, " - else - echo -n "[ subdir created, " - fi - fi - echo " OK ]" - done + 1) + echo "No deletion on warnings " + ;; + *) + echo "[ zip file corrupted, failed ]" + rm -rf $dir > /dev/null 2>&1 + continue + ;; + esac + + if [[ $createdir ]]; then + echo -n "[ subdir created, " + elif [[ $nodir ]]; then + mv ./$dir/* ./ && rmdir $dir + echo -n "[ No subdir, " + else + subdirs=$(find $dir -maxdepth 1 | wc -l) + if [[ $subdirs -eq 2 ]]; then + mv ./$dir/* ./ && rmdir $dir + echo -n "[ No subdir, " + else + echo -n "[ subdir created, " + fi + fi + echo " OK ]" + done done } export utaz @@ -619,168 +628,168 @@ taz() { _doxz() { - command -v xz >/dev/null 2>&1 || { - echo -e >&2 "\t*** The program 'xz' is not installed, aborting." - return 127 - } - - [[ $4 ]] && local verb='-v' + command -v xz >/dev/null 2>&1 || { + echo -e >&2 "\t*** The program 'xz' is not installed, aborting." + return 127 + } - # Display a warning for this format - echo -e "\t! Warning: xz format is not suited for long term archiving." - echo -e "\t See https://www.nongnu.org/lzip/xz_inadequate.html for details." + [[ $4 ]] && local verb='-v' - # Compresse to xz (lzma2) - Deprecated - xz $verb --compress --keep -$3 -T $2 $1 - return $? + # Display a warning for this format + echo -e "\t! Warning: xz format is not suited for long term archiving." + echo -e "\t See https://www.nongnu.org/lzip/xz_inadequate.html for details." + + # Compresse to xz (lzma2) - Deprecated + xz $verb --compress --keep -$3 -T $2 $1 + return $? } _dolz() { - local procopt="--threads $2" - local command=plzip - - command -v plzip >/dev/null 2>&1 || { - command -v lzip >/dev/null 2>&1 || { - echo -e >&2 "\t*** Program 'plzip' or 'lzip' are not installed, aborting." - return 127 - } - local command=lzip - local procopt="" - [[ $2 -gt 1 ]] && - echo -e "\t! Warning: lzip doesn't support multithreading, falling back to 1 thread." && - exho -e "\t* Consitder installing plzip to obtain multithreading abilities." - } - - [[ $4 ]] && local verb="-vv" + local procopt="--threads $2" + local command=plzip - # Compresse au format lzip (lzma) - $command $verb $procopt --keep -$3 $1 - return $? + command -v plzip >/dev/null 2>&1 || { + command -v lzip >/dev/null 2>&1 || { + echo -e >&2 "\t*** Program 'plzip' or 'lzip' are not installed, aborting." + return 127 + } + local command=lzip + local procopt="" + [[ $2 -gt 1 ]] && + echo -e "\t! Warning: lzip doesn't support multithreading, falling back to 1 thread." && + echo -e "\t* Consitder installing plzip to obtain multithreading abilities." + } + + [[ $4 ]] && local verb="-vv" + + # Compresse au format lzip (lzma) + $command $verb $procopt --keep -$3 $1 + return $? } _dogz() { - local procopt="--processes $2" - local command=pigz + local procopt="--processes $2" + local command=pigz - command -v pigz >/dev/null 2>&1 || { - command -v gzip >/dev/null 2>&1 || { - echo -e >&2 "\t*** Programs 'pigz' or 'gzip' are not installed, aborting." - return 127 - } - local command="gzip --compress" - local procopt="" - [[ $2 -gt 1 ]] && - echo -e "\t! Warning: gzip doesn't support multithreading, falling back to 1 thread." && - exho -e "\t* Consitder installing pigz to obtain multithreading abilities." - } + command -v pigz >/dev/null 2>&1 || { + command -v gzip >/dev/null 2>&1 || { + echo -e >&2 "\t*** Programs 'pigz' or 'gzip' are not installed, aborting." + return 127 + } + local command="gzip --compress" + local procopt="" + [[ $2 -gt 1 ]] && + echo -e "\t! Warning: gzip doesn't support multithreading, falling back to 1 thread." && + echo -e "\t* Consitder installing pigz to obtain multithreading abilities." + } - [[ $4 ]] && local verb="--verbose" + [[ $4 ]] && local verb="--verbose" - # Compresse au format bz2 - $command $verb $procopt --keep -$3 $1 - return $? + # Compresse au format bz2 + $command $verb $procopt --keep -$3 $1 + return $? } _dobz2() { - local procopt="-p$2" - local command=pbzip2 + local procopt="-p$2" + local command=pbzip2 - command -v pbzip2 >/dev/null 2>&1 || { - command -v bzip2 >/dev/null 2>&1 || { - echo -e >&2 "\t*** The program 'pbzip2' or 'bzip2' are not installed, aborting." - return 127 - } - local command=bzip2 - local procopt="" - [[ $2 -gt 1 ]] && - echo -e "\t! Warning: bzip2 doesn't support multithreading, falling back to 1 thread." && - exho -e "\t* Consitder installing pbzip2 to obtain multithreading abilities." - } + command -v pbzip2 >/dev/null 2>&1 || { + command -v bzip2 >/dev/null 2>&1 || { + echo -e >&2 "\t*** The program 'pbzip2' or 'bzip2' are not installed, aborting." + return 127 + } + local command=bzip2 + local procopt="" + [[ $2 -gt 1 ]] && + echo -e "\t! Warning: bzip2 doesn't support multithreading, falling back to 1 thread." && + echo -e "\t* Consitder installing pbzip2 to obtain multithreading abilities." + } - [[ $4 ]] && local verb="-v" + [[ $4 ]] && local verb="-v" - # Compresse au format bz2 - $command $verb --compress $procopt --keep -$3 $1 - return $? + # Compresse au format bz2 + $command $verb --compress $procopt --keep -$3 $1 + return $? } _dolzo() { - command -v lzop >/dev/null 2>&1 || { - echo -e >&2 "\t*** The program 'lzop' is not installed, aborting." - return 127 - } - - [[ $4 ]] && local verb='-v' - [[ $2 -gt 1 ]] && echo -e "\t! Warning: lzop doesn't support multithreading, falling back to 1 thread." - - # Compresse au format lzo - lzop --keep -$3 $1 - return $? + command -v lzop >/dev/null 2>&1 || { + echo -e >&2 "\t*** The program 'lzop' is not installed, aborting." + return 127 + } + + [[ $4 ]] && local verb='-v' + [[ $2 -gt 1 ]] && echo -e "\t! Warning: lzop doesn't support multithreading, falling back to 1 thread." + + # Compresse au format lzo + lzop --keep -$3 $1 + return $? } for opt in $@ ; do - case $opt in - "-h"|"--help") - echo "taz : archive all files of a directory." - echo - echo "Usage: taz [option] [--parallel=] [--format=] [directory1 ... directoryN]" - echo - echo "Options:" - echo " -h, --help Display that help screen" - echo " -d, --delete Delete source file or directory after success" - echo " -f, --format Chose archive format in the given list. If several format are" - echo " given, the smalest is kept" - echo " -p, --parallel Number of threads to use (if allowed by underlying utility)" - echo " -v, --verbose Display progress where possible" - echo " -1, .., -9 Compression level to use [1=fast/big, 9=slow/small]" - echo - echo "Supported archive format:" - echo " Param.| programs | Algo. | Description" - echo " ------+---------------+-------+----------------------------------------" - echo " lz | plzip, lzip | lzma | Safe efficient default format" - echo " xz | xz | lzma2 | Unsafe, not for long term" - echo " bz2 | pbzip2, bzip2 | bzip2 | Historical but less efficient than lz" - echo " gz | pigz, gzip | lz77 | Historical, safe, fast" - echo " lzo | lzop | lzo | Very fast but no multithread" - echo " tar | tar | tar | No compression" - echo - return 0 - ;; + case $opt in + "-h"|"--help") + echo "taz : archive all files of a directory." + echo + echo "Usage: taz [option] [--parallel=] [--format=] [directory1 ... directoryN]" + echo + echo "Options:" + echo " -h, --help Display that help screen" + echo " -d, --delete Delete source file or directory after success" + echo " -f, --format Chose archive format in the given list. If several format are" + echo " given, the smalest is kept" + echo " -p, --parallel Number of threads to use (if allowed by underlying utility)" + echo " -v, --verbose Display progress where possible" + echo " -1, .., -9 Compression level to use [1=fast/big, 9=slow/small]" + echo + echo "Supported archive format:" + echo " Param.| programs | Algo. | Description" + echo " ------+---------------+-------+----------------------------------------" + echo " lz | plzip, lzip | lzma | Safe efficient default format" + echo " xz | xz | lzma2 | Unsafe, not for long term" + echo " bz2 | pbzip2, bzip2 | bzip2 | Historical but less efficient than lz" + echo " gz | pigz, gzip | lz77 | Historical, safe, fast" + echo " lzo | lzop | lzo | Very fast but no multithread" + echo " tar | tar | tar | No compression" + echo + return 0 + ;; - "-d"|"--delete") - local willrm=1 - ;; + "-d"|"--delete") + local willrm=1 + ;; - "-f"?*|"--format"?*) - local compform=$(echo "$opt" | cut -f 2- -d '=') - ;; + "-f"?*|"--format"?*) + local compform=$(echo "$opt" | cut -f 2- -d '=') + ;; - "-p"?*|"--parallel"?*) - local nproc=$(echo "$opt" | cut -f 2- -d '=') - ;; + "-p"?*|"--parallel"?*) + local nproc=$(echo "$opt" | cut -f 2- -d '=') + ;; - "-v"|"--verbose") - local verbose=1 - ;; + "-v"|"--verbose") + local verbose=1 + ;; - "-"[1..9]) - local complevel=${opt:1:1} - ;; + "-"[1..9]) + local complevel=${opt:1:1} + ;; - "-"*) - echo "Invalid option, use taz --help to display options list" - echo - return 1 - ;; + "-"*) + echo "Invalid option, use taz --help to display options list" + echo + return 1 + ;; - *) - local LIST="$LIST ${opt%/}" - ;; - esac + *) + local LIST="$LIST ${opt%/}" + ;; + esac done [[ ! $compform ]] && compform=lz # safe and efficient (unless data are already compressed) @@ -788,51 +797,50 @@ taz() [[ ! $complevel ]] && complevel=6 for item in $LIST; do - local donetar=0 - echo "--- Processing $item..." + local donetar=0 + echo "--- Processing $item..." - if [[ -d $item ]]; then - echo -ne "\t* Creating $item.tar... " + if [[ -d $item ]]; then + echo -ne "\t* Creating $item.tar... " - tar -cf $item{.tar,} - if [[ ! $? -eq 0 ]]; then - echo "[ failed, skipping ]" - continue - fi + tar -cf $item{.tar,} + if [[ ! $? -eq 0 ]]; then + echo "[ failed, skipping ]" + continue + fi - local donetar=1 - echo "[ OK ]" - fi - - local fname=$item - [[ $donetar -gt 0 ]] && fname=$item.tar + local donetar=1 + echo "[ OK ]" + fi - # Skip compression part if tar is asked - if [[ $compform != "tar" ]]; then - echo -e "\t* Compressing archive..." - _do$compform $fname $nproc $complevel $verbose - [[ ! $? -eq 0 ]] && case $? in - 127) - echo -e "\t*** Compression program unavailable, aborting." - return 127 - ;; - *) - echo -e "\t*** Compression program returned an error, not deleting anything if asked, skipping to next item." - continue - ;; - esac + local fname=$item + [[ $donetar -gt 0 ]] && fname=$item.tar - [[ $donetar -gt 0 ]] && rm $fname - fi + # Skip compression part if tar is asked + if [[ $compform != "tar" ]]; then + echo -e "\t* Compressing archive..." + _do$compform $fname $nproc $complevel $verbose + [[ ! $? -eq 0 ]] && case $? in + 127) + echo -e "\t*** Compression program unavailable, aborting." + return 127 + ;; + *) + echo -e "\t*** Compression program returned an error, not deleting anything if asked, skipping to next item." + continue + ;; + esac - if [[ $willrm ]]; then - echo -en "\t* Deleting original source as asked... " - rm -r $item && echo '[ OK ]' || echo '[ failed ]' - fi + [[ $donetar -gt 0 ]] && rm $fname + fi - echo "--- Done" + if [[ $willrm ]]; then + echo -en "\t* Deleting original source as asked... " + rm -r $item && echo '[ OK ]' || echo '[ failed ]' + fi + + echo "--- Done" done - } export taz @@ -858,48 +866,47 @@ ksession() { # Restore if asked to if [[ "$1" = "restore" ]]; then - - echo "Restoring..." - konsole --tabs-from-file $savefile -e 'bash -c exit' & - + + echo "Restoring..." + konsole --tabs-from-file $savefile -e 'bash -c exit' & + elif [[ "$1" = "save" ]]; then - pid=$(pgrep konsole -u $USER) - if [[ $pid ]]; then - echo "# Most recent session list " $(date) > $savefile - for p in $pid; do - local sessions=$(qdbus org.kde.konsole-$p | grep /Sessions/) - if [[ $sessions ]] ; then - [[ ! -d $savepath ]] && mkdir $savepath - for i in $sessions; do - local format=$(qdbus org.kde.konsole-$p $i tabTitleFormat 0) - local processid=$(qdbus org.kde.konsole-$p $i processId) - local cwd=$(pwdx $processid | sed -e "s/^[0-9]*: //") - if [[ $(pgrep --parent $processid) ]] ; then - childpid=$(pgrep --parent $processid) - command=$(ps -p $childpid -o args=) - fi - echo "workdir: ${cwd};; title: ${format};; command:${command}" >> ${savefile} - command='' - done - fi - done - fi - + pid=$(pgrep konsole -u $USER) + if [[ $pid ]]; then + echo "# Most recent session list " $(date) > $savefile + for p in $pid; do + local sessions=$(qdbus org.kde.konsole-$p | grep /Sessions/) + if [[ $sessions ]] ; then + [[ ! -d $savepath ]] && mkdir $savepath + for i in $sessions; do + local format=$(qdbus org.kde.konsole-$p $i tabTitleFormat 0) + local processid=$(qdbus org.kde.konsole-$p $i processId) + local cwd=$(pwdx $processid | sed -e "s/^[0-9]*: //") + if [[ $(pgrep --parent $processid) ]] ; then + childpid=$(pgrep --parent $processid) + command=$(ps -p $childpid -o args=) + fi + echo "workdir: ${cwd};; title: ${format};; command:${command}" >> ${savefile} + command='' + done + fi + done + fi else - echo "ksession: save and restore KDE's Konsole sessions" - echo - echo "Usage: ksession " + echo "ksession: save and restore KDE's Konsole sessions" + echo + echo "Usage: ksession " fi } export ksession -# ------------------------------------------------------------------------------------------ -# ------------------------------------------------------------------------------------------ -# **************************************** MAIN PROGRAM ************************************ -# ------------------------------------------------------------------------------------------ -# ------------------------------------------------------------------------------------------ +# ------------------------------------------------------------------------------ +# ------------------------------------------------------------------------------ +# ********************************** MAIN PROGRAM ****************************** +# ------------------------------------------------------------------------------ +# ------------------------------------------------------------------------------ # Former PS1, stopped for much better function # Set the prompt look'n'feel @@ -931,7 +938,7 @@ export PAGER=less # Execute optionnal config script if any for script in ~/profile.d/*.sh ; do if [ -r $script ] ; then - . $script + . $script fi done