|
From: | Florian Mayer |
Subject: | PROMPT_COMMAND and PS1 error |
Date: | Sun, 25 Oct 2015 17:10:38 +0100 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 |
Hello, I'm currently finishing my work building my own "prompt-lib". This, of course, involves manipulating the variables PROMPT_COMMAND and PS{1,2}. Problem description: Imagine a new interactive session where you source one file (first.sh). first.sh also sources another file (second.sh) which creates a global associative array. The interactive session now contains a function "sl-get" which should emit a "prompt". It echos either "0" or "1" depending on whether the date (exact to the minute) has changed since the last call to this function. Now PS1 should get updated every new command. PROMPT_COMMAND obviously is the variable to use here. So $ PROMPT_COMMAND=sl-set-prompt should do the trick... But, sadly, it doesn't. Strangely though, the value in "FOO" gets updated if you manually call sl-get. For better understanding, I appended the snippets I used to reproduce the problem. Further diagnosis information: Bash version: 4.3.42(1)-release (x86_64-unknown-linux-gnu) Operating System: Arch linux ==== file: first.sh ==== . second.sh sl-get(){ sl-set sl-notify-change echo $? } sl-set-prompt(){ PS1=$(sl-get)" >>" } ==== file end ==== ==== file: second.sh ==== declare -Ag FOO FOO=( ["data"]="" ["oldval"]="" ) sl-set(){ FOO["data"]=$(date "+%d.%m.%y-%H:%M") return 0 } sl-notify-change(){ if [ "${FOO["oldval"]}" != "${FOO["data"]}" ]; then FOO["oldval"]=${FOO["data"]} return 0 else return 1 fi } ==== file end ==== Best regards Florian Mayer |
[Prev in Thread] | Current Thread | [Next in Thread] |