Having been in this situation (the only binary I could use was bash
, although cd
was a bash builtin for me), echo *
is your friend. Even better is something like this:
get_path_type() {
local item
item="$1"
[[ -z "$item" ]] && { echo 'wrong arg count passed to get_path_type'; return 1; }
if [[ -d "$item" ]]; then
echo 'dir'
elif [[ -f "$item" ]]; then
echo 'file'
elif [[ -h "$item" ]]; then
echo 'link' # not accurate, but symlink is too long
else
echo '????'
fi
}
print_path_listing() {
local path path_type
path="$1"
[[ -z "$path" ]] && { echo 'wrong arg count passed to print_path_listing'; return 1; }
path_type="$(get_path_type "$path")"
printf '%s\t%s\n' "$path_type" "$path"
}
ls() {
local path paths item symlink_regex
paths=("$@")
if ((${#paths[@]} == 0)); then
paths=("$(pwd)")
fi
shopt -s dotglob
for path in "${paths[@]}"; do
if [[ -d "$path" ]]; then
printf '%s\n' "$path"
for item in "$path"/*; do
print_path_listing "$item"
done
elif [[ -e "$path" ]]; then
print_path_listing "$path"
printf '\n'
fi
done
}
This is recreated from memory and will likely have several nasty bugs. I also wrote it and quickly tested it entirely on my phone which was a bit painful. It should be pure bash, so it'll work in this type of situation.
EDIT: I'm bored and sleep deprived and wanted to do something, hence this nonsense. I've taken the joke entirely too seriously.