根据是否设置环境变量更改bash提示

时间:2015-08-06 06:36:00

标签: bash .bash-profile

我试图让PS1在设置环境变量时发生变化

我尝试过这两种方法但没有成功:

PS1_EMOJI=
update_ps1_emoji() {
  if [ "$ENV_VAR" != "" ]; then
    PS1_EMOJI=
  fi
}

PROMPT_COMMAND='update_ps1_emoji'
export PS1="\[\e[0;35m\]$PS1_EMOJI [\W]\$?\[\e[m\e[0;31m\]$\[\e[m\] "

ps1_emoji() {
  if [ "$ENV_VAR" != "" ]; then
    echo -n ""
  else
    echo -n ""
  fi
}
export PS1="\[\e[0;35m\]`ps1_emoji` [\W]\$?\[\e[m\e[0;31m\]$\[\e[m\] "

设置环境变量并重新获取.bashrc会更新提示。

1 个答案:

答案 0 :(得分:4)

试试这个:

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.samko.controlit"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="16"
        android:targetSdkVersion="21" />

    <uses-permission
        android:name="android.permission.TRANSMIT_IR"
        android:required="false" />
    <uses-permission
        android:name="android.permission.VIBRATE"
        android:required="false" />
   <!-- <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" /> -->

    <uses-feature android:name="android.hardware.consumerir" />

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="com.android.vending.BILLING" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.USE_CREDENTIALS" />

    <permission
        android:name="com.samko.controlit.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />

    <uses-permission android:name="com.samko.controlit.permission.C2D_MESSAGE" />

<强>演示

export PS1_EMOJI=1
ps1_emoji() {
    echo "checking TEST-var"
    if [ -z "$TEST" ]; then
        echo "TEST is empty!"
        export PS1_EMOJI=2
    else
        echo "TEST is not empty"
        export PS1_EMOJI=1
    fi
}
PROMPT_COMMAND='ps1_emoji'

export PS1="\$PS1_EMOJI $"