Skip to content

Instantly share code, notes, and snippets.

@konsolebox
Last active June 14, 2024 19:24
Show Gist options
  • Save konsolebox/799327edba034a61852b51f7bff19700 to your computer and use it in GitHub Desktop.
Save konsolebox/799327edba034a61852b51f7bff19700 to your computer and use it in GitHub Desktop.
function ls {
local orig_args=("$@") d_opt=()
local -i argc=0
while [[ $# -gt 0 ]]; do
case $1 in
-[aAbBcCdDfgGhHiklLmnNorRsStuUvxXZ1]|--all|--almost-all|--author|--context|--dereference|--dereference-command-line|--dereference-command-line-symlink-to-dir|--directory|--dired|--file-type|--full-time|--group-directories-first|--help|--hide-control-chars|--human-readable|--ignore-backups|--inode|--kibibytes|--literal|--no-group|--numeric-uid-gid|--quote-name|--recursive|--reverse|--show-control-chars|--size|--version|--zero)
;;
-[ITpw]*|@(--block-size|--format|--hide|--ignore|--indicator-style|--indicator-style|--quoting-style|--sort|--tabsize|--time|--time-style|--width)?(=*))
get_opt_and_optarg_gnu "${@:1:2}"
shift "${OPTSHIFT}"
;;
-F*|@(--color|--classify|--hyperlink)?(=*))
get_opt_and_optarg_gnu @optional "${@:1:2}"
shift "${OPTSHIFT}"
;;
--)
shift
argc+="$#"
break
;;
-[!-][!-]*)
set -- "${1:0:2}" "-${1:2}" "${@:2}"
continue
;;
-?*)
echo "Unrecognized ls option: $1" >&2
echo "If this is a valid option, update the wrapper function." >&2
return 2
;;
*)
argc+=1
;;
esac
shift
done
[[ argc -ge 2 ]] && d_opt=(-d)
command ls --literal --color=always -C "${d_opt[@]}" "${orig_args[@]}" | less -SFR
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment