Skip to content

Commit

Permalink
elsi.sh, ewd.sh: simplity
Browse files Browse the repository at this point in the history
  • Loading branch information
ko1nksm committed Nov 14, 2019
1 parent c1b2c18 commit 9ec5957
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 48 deletions.
30 changes: 12 additions & 18 deletions share/lsi.sh
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
#shellcheck shell=sh

translate=unix
unix=1 mixed=''

usage() {
cat<<HERE
Usage: elsi [options]
options:
-u Print a Unix path (default)
-w Print a Windows path
-m Print a Windows, with '/' instead of '\'
-u, --unix Print a Unix path (default)
-w, --windows Print a Windows path
-m, --mixed Print a Windows, with '/' instead of '\'
HERE
exit
}

for arg in "$@"; do
case $arg in
-u | --unix) translate=unix ;;
-w | --windows) translate=windows ;;
-m | --mixed) translate=mixed ;;
-u | --unix) unix=1 mixed='' ;;
-w | --windows) unix='' mixed='' ;;
-m | --mixed) unix='' mixed=1 ;;
-h | --help) usage ;;
esac
done
Expand All @@ -30,18 +30,12 @@ abort() {

lsi() (
cd "$EOPEN_ROOT" || exit 1
bin/ebridge.exe lsi
bin/ebridge.exe lsi "$@"
)

lsi | while IFS= read -r item; do
case $translate in
windows) ;;
unix) item=$(to_linpath "$item");;
mixed)
IFS='\'
set -- $item
IFS='/'
item=$*
esac
[ "$mixed" ] && options=m || options=''

lsi "$options" | while IFS= read -r item; do
[ "$unix" ] && item=$(to_linpath "$item")
printf '%s\n' "$item"
done
51 changes: 21 additions & 30 deletions share/wd.sh
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
#shellcheck shell=sh

translate=unix
unix=1 mixed=''

usage() {
cat<<HERE
Usage: ewd [options]
options:
-u Print a Unix path (default)
-w Print a Windows path
-m Print a Windows, with '/' instead of '\'
-u, --unix Print a Unix path (default)
-w, --windows Print a Windows path
-m, --mixed Print a Windows, with '/' instead of '\'
HERE
exit
}

for arg in "$@"; do
case $arg in
-u | --unix) translate=unix ;;
-w | --windows) translate=windows ;;
-m | --mixed) translate=mixed ;;
-u | --unix) unix=1 mixed='' ;;
-w | --windows) unix='' mixed='' ;;
-m | --mixed) unix='' mixed=1 ;;
-h | --help) usage ;;
esac
done
Expand All @@ -28,32 +28,23 @@ abort() {
exit 1
}

[ "$mixed" ] && options=m || options=''

ewd=$(
cd "$EOPEN_ROOT" || exit 1
bin/ebridge.exe pwd
bin/ebridge.exe pwd auto "$options"
) || abort

case $translate in
unix)
case $ewd in ([A-Za-z]:* | \\\\*)
if dest=$(to_linpath "$ewd") 2>/dev/null; then
printf '%s\n' "$dest"
exit 0
fi
esac
;;
mixed)
IFS='\'
set -- $ewd
IFS='/'
ewd=$*
printf '%s\n' "$ewd"
exit 0
;;
windows)
printf '%s\n' "$ewd"
exit 0
;;
esac
if [ "$unix" ]; then
case $ewd in ([A-Za-z]:* | \\\\*)
if dest=$(to_linpath "$ewd") 2>/dev/null; then
printf '%s\n' "$dest"
exit 0
fi
esac
else
printf '%s\n' "$ewd"
exit 0
fi

abort "Unsupported path '$ewd'"

0 comments on commit 9ec5957

Please sign in to comment.