DEV Community

Discussion on: Can I see your terminal?

Collapse
 
jacoby profile image
Dave Jacoby

It helps if you have Font Awesome set up on your system.

This needs cleaning up. As pasted from my prompt.sh

# prompt.sh

# the unified prompt for Dave Jacoby, based on system settings
# and capabilities.

# if a capability is absent for an entry, such as TaskWarrior
# or ACPI, the prompt will drop that in favor of entries it
# can handle.

# Tasks

#   * I have partially added Font Awesome to the prompt,
#     especially for the buttons. I need to more fully 
#     integrate FA fonts. For example, with TaskWarrior 
#     icons

# TASK WARRIOR INTO MY PROMPT
# this part is just fun-with-utf8
# https://twitter.com/pjf/status/852466839145795584
URGENT="2757"
DUETOMORROW="2690"
DUETODAY="2691"
OVERDUE="2639"
OK="2714"

# shows if any TaskWarrior tasks are in need of attention
function task_indicator {
    if [ `task +READY +OVERDUE count` -gt "0" ]  ; then
        printf "%b" "\u$OVERDUE"
    elif [ `task +READY +DUETODAY count` -gt "0" ]  ; then
        printf "%b" "\u$DUETODAY"
    elif [ `task +READY +DUETomorrow count` -gt "0" ]  ; then
        printf "%b" "\u$DUETOMORROW"
    elif [ `task +READY urgency \> 10 count` -gt "0" ]  ; then
        printf "%b" "\u$URGENT"
    else
        printf "%b" "\u$OK"
    fi
}

# here I switch to Font-Awesome, which might not show for dev.to
HOT_BEVERAGE="2615"
POWER="26A1"
#BATTERY="8984"
#POWER="2605"
BATTERY="2606"
NOT=""
fa_bolt=""
fa_plug="" # fa-plug [&#xf1e6
fa_battery="" # fa-battery (alias) [] 4.4
fa_battery_0="" # fa_battery_0 (alias) [] 4.4
fa_battery_1="" # fa_battery_1 (alias) [] 4.4
fa_battery_2="" # fa_battery_2 (alias) [] 4.4
fa_battery_3="" # fa_battery_3 (alias) [] 4.4
fa_battery_4="" # fa_battery_4 (alias) [] 4.4
fa_battery_empty="" # fa_battery_empty [] 4.4
fa_battery_full="" # fa_battery_full [] 4.4
fa_battery_half="" # fa_battery_half [] 4.4
fa_battery_quarter="" # fa_battery_quarter [] 4.4
fa_battery_three="" # fa_battery_three-quarters [] 4.3 fa-bed [&

# PLUGGED IN OR NO
# works on my Linux laptop, not on my desktop

# shows if the battery is currently charging
function battery_charging {
    CHARGING=`/usr/bin/acpi | awk '{ print $3}'`
    if [ $CHARGING = 'Discharging,' ];  then
        printf '%s' $fa_plug
    else
        printf '%s' $fa_bolt
    fi
}

# shows current status of battery
# 0  - 12     EMPTY
# 13 - 37     QUARTER
# 38 - 62     HALF
# 63 - 87     THREE-QUARTER
# 88 - 100    FULL
function battery_life {
    ACPI=`/usr/bin/acpi | awk '{ print $4}'`
    ACPI=${ACPI//[!0-9]/}
    if   [ $ACPI == "100" ];then 
        printf '%s ' $fa_battery_4
    elif [   $ACPI -lt "13" ];then
        printf '%s ' $fa_battery_0
    elif [ $ACPI -lt "38" ];then
        printf '%s ' $fa_battery_1
    elif [ $ACPI -lt "63" ];then
        printf '%s ' $fa_battery_2
    elif [ $ACPI -lt "88" ];then
        printf '%s ' $fa_battery_3
    else 
        printf '%s ' $fa_battery_4
    fi    
}

# opening tag for setting color. depends on a lot of
# variations, including host
function opentag {
    if [ -f "/bin/hostname" ] ; then
        HOST=`/bin/hostname`
    else
        HOST='NONE'
    fi

    if [[ $HOST == *"purdue.edu" ]] ; then
        HOST=`/bin/hostname -s`
    fi

    foreground='38;5;255'
    background=''
    bold='1;'   #1
    dim=''      #2
    italic=''   #3
    reverse=''  #7

    # WORK LINUX COMPUTER
    if [ $HOST = 'oz' ]; then
        foreground='38;5;82'
        bold='1;'
        if [[ -z $DESKTOP_SESSION ]] ; then
            reverse='7;'
        fi

    # WORK WINDOWS 10 COMPUTER 
    elif [ $HOST = 'Lion' ];then
        foreground='38;5;206'
        foreground='38;5;79'
        bold='1;'
        # if [ -z $SYSTEMDRIVE ] ; then
        #    foreground='38;5;196'
        #     bold='1;'
        # fi

    # PERSONAL LINUX COMPUTER
    elif [ $HOST = 'gort' ]; then
        foreground='38;5;39'
        bold='1;'

    # PERSONAL WIN10 COMPUTER
    # works in WSL, not in Git4Windows Bash
    elif [ $HOST = 'K9' ]; then
        foreground='38;5;39'
        bold='1;'

    # REMOVING SOME WORK HOSTS
    fi
    printf "\e[%s%s%s%s%sm" $bold $dim $italic $reverse $background $foreground
    # unset HOST foreground background bold dim italic reverse 
}

# closes all open tag types
function closetag {
    printf "\e[0m"
    }

# if wanted, just bold and white
function boldwhite {
    printf "\e\[1;38;5;255m"
    }

# sets the PS1 variable
# function set_ps1 {

    header="\[\033]0;\u@\h: \w\007\]"
    # chroot="${debian_chroot:+($debian_chroot)}"
    chroot=""
    userhost="\u@\h "
    localtime="\A "
    path="\w "
    end="\n\$ "

    # the coffee, weather and reboot info are called in other programs
    # every time the prompt is run
    task="\$(task_indicator)"
    battery_charging="\$(battery_charging)"
    battery_life="\$(battery_life)"
    timer_show="($timer_show)"
    reboot="\$(~/bin/need_reboot.pl)"
    temp="\$(~/bin/get_temp.pl)"
    coffee="\$(~/bin/get_coffee.pl) "
    dbus="\$(~/local/bin/pull_dbus_address.sh)"
    git="\$(__git_ps1)"

    open="$(opentag)"
    close="$(closetag)"

    prompt=$header

    # I add getting and storing the DBUS address so I can 
    # control Spotify from the command line and take webcam
    # pictures via Crontab
    if [ -f ~/local/bin/pull_dbus_address.sh ];then
        prompt="$prompt$dbus"
    fi

    prompt="$prompt\n\[$open\]"

    if [ -f ~/bin/need_reboot.pl ];then
        prompt="$prompt$reboot "
    fi

    if [ -f /usr/bin/acpi ];then
        prompt="$prompt$battery_charging "
        prompt="$prompt$battery_life "
    fi

    if [ -f /usr/bin/task ];then
        prompt="$prompt$task "
    fi

    prompt=$prompt$userhost
    prompt=$prompt$localtime

    if [ -f ~/bin/get_temp.pl ];then
        prompt="$prompt$temp "
    fi

    if [ -f ~/bin/get_coffee.pl ];then
        prompt="$prompt$coffee "
    fi

    prompt=$prompt$path
    prompt=$prompt$chroot
    prompt=$prompt$git

    if [ -f ~/.timing ];then
        prompt="$prompt$timer_show "
    fi

    prompt=$prompt$end
    prompt="$prompt\[$close\]"

    trap 'timer_start' DEBUG
    PROMPT_COMMAND="timer_stop"
    export PS1=$prompt
    # unset chroot close coffee dbus end git header open path prompt reboot task temp localtime userhost
# }

# set_ps1

and this in my .bashrc:

if [ -f /home/jacoby/bin/prompt.sh ]; then
    source /home/jacoby/bin/prompt.sh 
else
    export PS1="\n\
\[\033]0;\u@\h: \w\007\]\
${debian_chroot:+($debian_chroot)}\
\u@\h \
\A \
\$(~/bin/pull_dbus_address.sh)\w\$(__git_ps1)\
\n\$ "

fi
Thread Thread
 
kylegalloway profile image
Kyle Galloway

Thanks