-
Notifications
You must be signed in to change notification settings - Fork 2.3k
aliases/general & plugin/extract #2095
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
gaelicWizard
wants to merge
7
commits into
Bash-it:master
Choose a base branch
from
gaelicWizard:alias/general
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8e78294
aliases/general: cleanup
gaelicWizard f36793b
aliases/directory: split out directory shortcuts
gaelicWizard 18e27b7
aliases/editor: split out editor shortcuts
gaelicWizard f076319
aliases/general: move `xt` to `plugin/extract`
gaelicWizard 32523a5
plugin/extract: `shfmt`
gaelicWizard 1671df9
plugin/extract: `shellcheck`
gaelicWizard c39673c
Merge branch 'master' into alias/general
seefood File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# shellcheck shell=bash | ||
about-alias 'Shortcuts for directory commands: ls, cd, &c.' | ||
|
||
if command ls --color -d . &> /dev/null; then | ||
alias ls='ls --color=auto' | ||
# BSD `ls` doesn't need an argument (`-G`) when `$CLICOLOR` is set. | ||
fi | ||
|
||
# List directory contents | ||
alias sl=ls | ||
alias la='ls -AF' # Compact view, show hidden | ||
alias ll='ls -Al' | ||
alias l='ls -A' | ||
alias l1='ls -1' | ||
alias lf='ls -F' | ||
|
||
# Change directory | ||
alias ..='cd ..' # Go up one directory | ||
alias cd..='cd ..' # Common misspelling for going up one directory | ||
alias ...='cd ../..' # Go up two directories | ||
alias ....='cd ../../..' # Go up three directories | ||
alias -- -='cd -' # Go back | ||
|
||
# Create or remove directory | ||
alias md='mkdir -p' | ||
alias rd='rmdir' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# shellcheck shell=bash | ||
about-alias 'shortcuts for editing' | ||
|
||
alias edit='${EDITOR:-${ALTERNATE_EDITOR:-nano}}' | ||
alias e='edit' | ||
|
||
# sudo editors | ||
alias svim='sudo ${VISUAL:-vim}' | ||
alias snano='sudo ${ALTERNATE_EDITOR:-nano}' | ||
alias sedit='sudo ${EDITOR:-${ALTERNATE_EDITOR:-nano}}' | ||
|
||
# Shortcuts to edit startup files | ||
alias vbrc='${VISUAL:-vim} ~/.bashrc' | ||
alias vbpf='${VISUAL:-vim} ~/.bash_profile' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,84 @@ | ||
cite about-plugin | ||
# shellcheck shell=bash | ||
about-plugin 'one command to extract them all...' | ||
|
||
# extract file(s) from compressed status | ||
extract() { | ||
local opt | ||
local OPTIND=1 | ||
while getopts "hv" opt; do | ||
case "$opt" in | ||
h) | ||
cat <<End-Of-Usage | ||
function extract() { | ||
local opt OPTIND=1 verbose | ||
local filename filedirname targetdirname | ||
while getopts "hv" opt; do | ||
case "$opt" in | ||
h) | ||
cat << EOU | ||
Usage: ${FUNCNAME[0]} [option] <archives> | ||
options: | ||
-h show this message and exit | ||
-v verbosely list files processed | ||
End-Of-Usage | ||
return | ||
;; | ||
v) | ||
local -r verbose='v' | ||
;; | ||
?) | ||
extract -h >&2 | ||
return 1 | ||
;; | ||
esac | ||
done | ||
shift $((OPTIND-1)) | ||
EOU | ||
return | ||
;; | ||
v) | ||
local -r verbose='v' | ||
;; | ||
?) | ||
extract -h >&2 | ||
return 1 | ||
;; | ||
esac | ||
done | ||
shift $((OPTIND - 1)) | ||
|
||
[ $# -eq 0 ] && extract -h && return 1 | ||
while [ $# -gt 0 ]; do | ||
if [[ ! -f "$1" ]]; then | ||
echo "extract: '$1' is not a valid file" >&2 | ||
shift | ||
continue | ||
fi | ||
if [[ $# -eq 0 ]]; then | ||
extract -h | ||
return 1 | ||
fi | ||
|
||
local -r filename=$(basename -- $1) | ||
local -r filedirname=$(dirname -- $1) | ||
local targetdirname=$(sed 's/\(\.tar\.bz2$\|\.tbz$\|\.tbz2$\|\.tar\.gz$\|\.tgz$\|\.tar$\|\.tar\.xz$\|\.txz$\|\.tar\.Z$\|\.7z$\|\.nupkg$\|\.zip$\|\.war$\|\.jar$\)//g' <<< $filename) | ||
if [ "$filename" = "$targetdirname" ]; then | ||
# archive type either not supported or it doesn't need dir creation | ||
targetdirname="" | ||
else | ||
mkdir -v "$filedirname/$targetdirname" | ||
fi | ||
while [[ $# -gt 0 ]]; do | ||
if [[ ! -f "${1:-}" ]]; then | ||
echo "extract: '$1' is not a valid file" >&2 | ||
shift | ||
continue | ||
fi | ||
|
||
if [ -f "$1" ]; then | ||
case "$1" in | ||
*.tar.bz2|*.tbz|*.tbz2) tar "x${verbose}jf" "$1" -C "$filedirname/$targetdirname" ;; | ||
*.tar.gz|*.tgz) tar "x${verbose}zf" "$1" -C "$filedirname/$targetdirname" ;; | ||
*.tar.xz|*.txz) tar "x${verbose}Jf" "$1" -C "$filedirname/$targetdirname" ;; | ||
*.tar.Z) tar "x${verbose}Zf" "$1" -C "$filedirname/$targetdirname" ;; | ||
*.bz2) bunzip2 "$1" ;; | ||
*.deb) dpkg-deb -x${verbose} "$1" "${1:0:-4}" ;; | ||
*.pax.gz) gunzip "$1"; set -- "$@" "${1:0:-3}" ;; | ||
*.gz) gunzip "$1" ;; | ||
*.pax) pax -r -f "$1" ;; | ||
*.pkg) pkgutil --expand "$1" "${1:0:-4}" ;; | ||
*.rar) unrar x "$1" ;; | ||
*.rpm) rpm2cpio "$1" | cpio -idm${verbose} ;; | ||
*.tar) tar "x${verbose}f" "$1" -C "$filedirname/$targetdirname" ;; | ||
*.xz) xz --decompress "$1" ;; | ||
*.zip|*.war|*.jar|*.nupkg) unzip "$1" -d "$filedirname/$targetdirname" ;; | ||
*.Z) uncompress "$1" ;; | ||
*.7z) 7za x -o"$filedirname/$targetdirname" "$1" ;; | ||
*) echo "'$1' cannot be extracted via extract" >&2;; | ||
esac | ||
fi | ||
local -r filename=$(basename -- "$1") | ||
local -r filedirname=$(dirname -- "$1") | ||
# shellcheck disable=SC2001 # we don't depend on `extglob`... | ||
targetdirname=$(sed 's/\(\.tar\.bz2$\|\.tbz$\|\.tbz2$\|\.tar\.gz$\|\.tgz$\|\.tar$\|\.tar\.xz$\|\.txz$\|\.tar\.Z$\|\.7z$\|\.nupkg$\|\.zip$\|\.war$\|\.jar$\)//g' <<< "$filename") | ||
if [[ "$filename" == "$targetdirname" ]]; then | ||
# archive type either not supported or it doesn't need dir creation | ||
targetdirname="" | ||
else | ||
mkdir -v "$filedirname/$targetdirname" | ||
fi | ||
|
||
shift | ||
done | ||
if [[ -f "$1" ]]; then | ||
case "$1" in | ||
*.tar.bz2 | *.tbz | *.tbz2) tar "x${verbose}jf" "$1" -C "$filedirname/$targetdirname" ;; | ||
*.tar.gz | *.tgz) tar "x${verbose}zf" "$1" -C "$filedirname/$targetdirname" ;; | ||
*.tar.xz | *.txz) tar "x${verbose}Jf" "$1" -C "$filedirname/$targetdirname" ;; | ||
*.tar.Z) tar "x${verbose}Zf" "$1" -C "$filedirname/$targetdirname" ;; | ||
*.bz2) bunzip2 "$1" ;; | ||
*.deb) dpkg-deb -x"${verbose}" "$1" "${1:0:-4}" ;; | ||
*.pax.gz) | ||
gunzip "$1" | ||
set -- "$@" "${1:0:-3}" | ||
;; | ||
*.gz) gunzip "$1" ;; | ||
*.pax) pax -r -f "$1" ;; | ||
*.pkg) pkgutil --expand "$1" "${1:0:-4}" ;; | ||
*.rar) unrar x "$1" ;; | ||
*.rpm) rpm2cpio "$1" | cpio -idm"${verbose}" ;; | ||
*.tar) tar "x${verbose}f" "$1" -C "$filedirname/$targetdirname" ;; | ||
*.xz) xz --decompress "$1" ;; | ||
*.zip | *.war | *.jar | *.nupkg) unzip "$1" -d "$filedirname/$targetdirname" ;; | ||
*.Z) uncompress "$1" ;; | ||
*.7z) 7za x -o"$filedirname/$targetdirname" "$1" ;; | ||
*) echo "'$1' cannot be extracted via extract" >&2 ;; | ||
esac | ||
fi | ||
|
||
shift | ||
done | ||
} | ||
|
||
# Shorten extract | ||
alias xt='extract' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,6 @@ completion system | |
|
||
# aliases | ||
aliases general | ||
aliases bash-it | ||
aliases directory | ||
aliases editor |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
loading it here wont make it load it twice in case its enabled?
we can check if the alias is already enabled, and
source
only if its notThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one actually confused the heck out of me. If the user disabled it, we should not load it. If the user enabled it, we don't need to load it. How can we tell? No idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmm, I think that we should always check here if enabled, enable and source if not. If users dont want a certain alias, they should disable the general file. We can add a log here about it. I do not want to break backwards compat with this change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds right to me too.