Scripts: fixed realpath usage

master
Pierre Neidhardt 2013-12-27 11:17:55 +01:00
parent 29c81a2641
commit fbe8edddc6
7 changed files with 30 additions and 14 deletions

View File

@ -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()
{

View File

@ -72,9 +72,7 @@ _asciify()
}
if [ $# -ge 1 ]; then
for i; do
_asciify "$i"
done
_asciify "$@"
else
_asciify
fi

View File

@ -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" "$@"

View File

@ -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";;

View File

@ -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")"

View File

@ -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.

View File

@ -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'