Scripts: fixed realpath usage
parent
29c81a2641
commit
fbe8edddc6
|
@ -60,6 +60,13 @@ if [ $# -eq 0 ]; then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
## We need 'realpath' since we need to work on the real path for the input
|
||||
## files/folders and the archive location. Otherwise we could have troubles with
|
||||
## circular symlinks and so on.
|
||||
if ! command -v realpath >/dev/null; then
|
||||
echo >&2 "'realpath' is required."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
_archive()
|
||||
{
|
||||
|
|
|
@ -72,9 +72,7 @@ _asciify()
|
|||
}
|
||||
|
||||
if [ $# -ge 1 ]; then
|
||||
for i; do
|
||||
_asciify "$i"
|
||||
done
|
||||
_asciify "$@"
|
||||
else
|
||||
_asciify
|
||||
fi
|
||||
|
|
|
@ -44,7 +44,6 @@ done
|
|||
shift $(($OPTIND - 1))
|
||||
|
||||
if $OPT_TAIL; then
|
||||
# sed -n -e ":begin ; 1,${OPT_LINES}!{P;N;D} ; N ; b begin" $1
|
||||
sed -n -e ":begin ; 1,${OPT_LINES}!{P;N;D} ; N ; b begin" $1
|
||||
else
|
||||
sed -n -e "1,${OPT_LINES}!p" "$@"
|
||||
|
|
|
@ -60,8 +60,11 @@ command -v atool >/dev/null && echo "You should use atool instead." && echo
|
|||
_extract()
|
||||
{
|
||||
echo "[$1]"
|
||||
FOLDER="$(realpath "$1")"
|
||||
FOLDER="${FOLDER%/*}"
|
||||
case "$1" in
|
||||
*/*) FOLDER="${1%/*}";;
|
||||
*) FOLDER="." ;;
|
||||
esac
|
||||
|
||||
case "$1" in
|
||||
*.tar*|*.tbz2|*.tbz|*.tgz|*.txz) tar xf "$1" -C "$FOLDER" ;;
|
||||
*.7z) 7z x "$PASS" -o"$FOLDER" "$1";;
|
||||
|
|
|
@ -134,6 +134,13 @@ if [ $# -eq 0 ]; then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
if ! command -v realpath >/dev/null; then
|
||||
echo >&2 "'realpath' is required."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
## realpath is needed to check if image was already mounted or not.
|
||||
if $OPT_UNMOUNT; then
|
||||
for i ; do
|
||||
_umount "$(realpath "$i")"
|
||||
|
|
|
@ -12,19 +12,21 @@ ZDIRS="$HOME/.cache/zsh/dirs"
|
|||
## Fetch file location dynamically.
|
||||
if [ ! -f ~/.zshrc ]; then
|
||||
echo '~/.zshrc not found. Exiting.'
|
||||
exit
|
||||
fi
|
||||
if ! command -v realpath; then
|
||||
echo "'realpath' not found. Exiting."
|
||||
exit
|
||||
exit 1
|
||||
fi
|
||||
|
||||
## We need realpath to prevent us from adding duplicates to the zsh
|
||||
## DIRSTACKFILE.
|
||||
if ! command -v realpath; then
|
||||
echo "'realpath' not found. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
SHELL_DIR_GREP="$(grep "SHELL_DIR=" ~/.zshrc | cut -f2 -d=)"
|
||||
[ -n "$SHELL_DIR_GREP" ] && SHELL_DIR="$(eval echo "$SHELL_DIR_GREP")"
|
||||
if [ ! -d "$SHELL_DIR" ]; then
|
||||
echo 'SHELL_DIR not found. Could not search for DIRSTACKFILE. Exiting.'
|
||||
exit
|
||||
exit 1
|
||||
fi
|
||||
|
||||
ZDIRS_GREP="$(grep -rm1 'DIRSTACKFILE=' "$SHELL_DIR" | cut -f2 -d=)"
|
||||
|
@ -32,7 +34,7 @@ ZDIRS_GREP="$(grep -rm1 'DIRSTACKFILE=' "$SHELL_DIR" | cut -f2 -d=)"
|
|||
|
||||
if [ ! -f "$ZDIRS" ]; then
|
||||
echo 'DIRSTACKFILE not found. Exiting.'
|
||||
exit
|
||||
exit 1
|
||||
fi
|
||||
|
||||
## Prepend argument to zsh dirstack.
|
||||
|
|
|
@ -45,7 +45,7 @@ alias grep='grep --color=auto'
|
|||
[ ${#XDG_APPS} -ne 0 ] && alias applist='grep -R "^Name=" $XDG_APPS | cut -d'=' -f2 | sort'
|
||||
|
||||
## Remove executable attribute.
|
||||
alias nox='find * -type f -exec chmod a-x {} +'
|
||||
alias nox='find . -type f -exec chmod a-x {} +'
|
||||
|
||||
## Get your external IP.
|
||||
command -v curl >/dev/null && alias myip='curl ifconfig.me'
|
||||
|
|
Loading…
Reference in New Issue