Skip to content

Instantly share code, notes, and snippets.

@fish2000
Created April 24, 2018 00:16
Show Gist options
  • Save fish2000/4390f0152ab4c183e80ddf1a8b96c9ac to your computer and use it in GitHub Desktop.
Save fish2000/4390f0152ab4c183e80ddf1a8b96c9ac to your computer and use it in GitHub Desktop.
Bash 4.0+ function using Pythonpy
function pyls() {
if [ "$1" ]; then
attribute_count=$(py "len(dir(${1}))")
item_count=$(py "getattr(${1}, '__len__', lambda *a, **k: 0)()")
what_is_it=$(py "type(${1}).__name__")
echo -n "> Python ${what_is_it} “${1}” has ${item_count} member sub-items"
[ "${item_count}" -eq "0" ] && echo "" || echo ":"
# py ${1} | py -x '"+ %s" % x' -c 'print("")'
py ${1} | py -x '"+ %s" % x'
echo -n "> Python ${what_is_it} “${1}” has ${attribute_count} member attributes"
[ "${attribute_count}" -eq "0" ] && echo "" || echo ":"
py "sorted(dir(${1}))" | /usr/local/bin/columns -W `tput cols`
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment