Skip to content

2020

Bash Prompt and ls Alias

Prompt: [2020-03-13][23:49:21] [pi@raspberry:~]

  • Add at the end of ~/.profile
##### modify standard command prompt
# \n = new line; \u = current username; \w = current working dir (home = ~)
##### Colors
# Black       0;30     Dark Gray     1;30
# Blue        0;34     Light Blue    1;34
# Green       0;32     Light Green   1;32
# Cyan        0;36     Light Cyan    1;36
# Red         0;31     Light Red     1;31
# Purple      0;35     Light Purple  1;35
# Brown       0;33     Yellow        1;33
# Light Gray  0;37     White         1;37

export PS1="\[\033[0;33m\][\D{%Y-%m-%d}][\t]\[\033[0;36m\] [\u\[\033[0;37m\]@\[\033[0;36m\]\h:\[\033[0;32m\]\w]\[\033[0m\] \n$ "

##### Modify default ls command
# -G colorizes output
# -h makes sizes human readable
# -F throws a / after a directory, * after an executable, and a @ after a symlink
# -l listing format (as opposed to default wide)
# -a shows all files (even hidden)
alias ls='ls -laGFh'

Python Script to Get Local IPs

Python 3 Script to Get IPs

#!/usr/bin/env python3

def getips():
    import re
    import subprocess

    # get ip(s) from ifconfig
    found_ips = []
    ips = re.findall( r'[0-9]+(?:\.[0-9]+){3}', subprocess.getoutput("/sbin/ifconfig"))
    for ip in ips:
        if ip.startswith("255") or ip.startswith("127") or ip.endswith("255"):
            continue
        found_ips.append(ip)

    return ", ".join(found_ips)