From c1d5265018efa027591fe20b5d671a9737ba3d05 Mon Sep 17 00:00:00 2001 From: Ian Kelling Date: Fri, 17 Jun 2016 00:41:13 -0700 Subject: [PATCH] handle more files, simply removing function ver --- README | 4 ++-- ex | 38 +++++++++++++++++------------------ ex-function | 58 ----------------------------------------------------- 3 files changed, 20 insertions(+), 80 deletions(-) mode change 100755 => 100644 ex delete mode 100644 ex-function diff --git a/README b/README index b3829e2..0deabba 100644 --- a/README +++ b/README @@ -1,8 +1,8 @@ The main documentation is availiable via --help and near the top of any bash script files which sit next to this file. -Files ending in -function are for sourcing then calling as a function. Files -without -function are exactly the same except they are for calling as a script. +The script file can be stripped of the last line and used as a function +instead of a script. Patches, bugs, and any feedback is very welcome via gitorious or email to Ian Kelling . diff --git a/ex b/ex old mode 100755 new mode 100644 index 5ca021e..44bb462 --- a/ex +++ b/ex @@ -23,37 +23,35 @@ See source for exact file extensions." fi local x super for x in "$@"; do - case "$x" in - *.tar.bz2 | *.tbz2 ) tar xvjf "$x" ;; - *.tar.gz | *.tgz ) tar xvzf "$x" ;; - *.bz2 ) bunzip2 "$x" ;; - *.gz ) gunzip "$x" ;; - *.tar ) tar xvf "$x" ;; - *.zip ) unzip "$x" ;; - *.Z ) uncompress "$x" ;; - *.7z ) 7za x "$x" ;; - *.deb ) ar xv "$x" ;; - *.rpm ) rpm2cpio "$x" | cpio --extract --make-directories --verbose ;; - *.tar.xz ) tar Jxvf "$x" ;; + case "$x" in + *.tar.bz2 | *.tbz2 ) tar xjf "$x" ;; + *.tar.gz | *.tgz ) tar xzf "$x" ;; + *.bz2 ) bunzip2 "$x" ;; + *.gz ) gunzip "$x" ;; + *.tar ) tar xf "$x" ;; + *.zip ) unzip "$x" ;; + *.Z ) uncompress "$x" ;; + *.7z ) 7za x "$x" ;; + *.deb ) ar x "$x" ;; + *.rpm ) rpm2cpio "$x" | cpio --extract --make-directories ;; + *.tar.xz ) tar Jxf "$x" ;; + *.xz) xz -d "$x" ;; *.iso ) + local super if [[ $EUID != 0 ]]; then - if [[ $(sudo -v) == Sorry* ]]; then - echo error: need superuser priveledge for iso file - return 1 - fi super=sudo fi local temp_dir=$(mktemp -d) - losetup -f + $super losetup -f $super mount -o loop "$x" "$temp_dir" local dir="${x%%.iso}" mkdir "$dir" - cp -av "$temp_dir"/* "$dir" + cp -a "$temp_dir"/* "$dir" $super umount "$temp_dir" ;; *.r[0-9][0-9]|*.rar ) unrar x "$x" ;; - *) echo "I don't kno how to extract $x";; - esac + *) echo "I don't kno how to extract $x";; + esac done } ex "$@" diff --git a/ex-function b/ex-function deleted file mode 100644 index 7980023..0000000 --- a/ex-function +++ /dev/null @@ -1,58 +0,0 @@ -#!/bin/bash -# Copyright (C) 2014 Ian Kelling - -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at - -# http://www.apache.org/licenses/LICENSE-2.0 - -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -ex() { - local help="Usage: ex [--help] FILE... -Extract each FILE according to its extension. -7z bz2 deb gz iso rar rpm tar xz zip & variations. -See source for exact file extensions." - if [[ $1 == --help ]]; then - echo "$help" - fi - local x super - for x in "$@"; do - case "$x" in - *.tar.bz2 | *.tbz2 ) tar xvjf "$x" ;; - *.tar.gz | *.tgz ) tar xvzf "$x" ;; - *.bz2 ) bunzip2 "$x" ;; - *.gz ) gunzip "$x" ;; - *.tar ) tar xvf "$x" ;; - *.zip ) unzip "$x" ;; - *.Z ) uncompress "$x" ;; - *.7z ) 7za x "$x" ;; - *.deb ) ar xv "$x" ;; - *.rpm ) rpm2cpio "$x" | cpio --extract --make-directories --verbose ;; - *.tar.xz ) tar Jxvf "$x" ;; - *.iso ) - if [[ $EUID != 0 ]]; then - if [[ $(sudo -v) == Sorry* ]]; then - echo error: need superuser priveledge for iso file - return 1 - fi - super=sudo - fi - local temp_dir=$(mktemp -d) - losetup -f - $super mount -o loop "$x" "$temp_dir" - local dir="${x%%.iso}" - mkdir "$dir" - cp -av "$temp_dir"/* "$dir" - $super umount "$temp_dir" - ;; - *.r[0-9][0-9]|*.rar ) unrar x "$x" ;; - *) echo "I don't kno how to extract $x";; - esac - done -} -- 2.30.2