Powerlevel9k: Best way to update MULTILINE_SECOND_PROMPT_PREFIX??

Created on 22 Mar 2017  Â·  11Comments  Â·  Source: Powerlevel9k/powerlevel9k

I'm trying to do what seems to be simple, but I also seem to be having a simple bug that I'm having a had time addressing. This may just be a zsh question, but I'm asking it here because of the expertise regarding all of the components involved (zsh, oh-my-zsh, powerlevel9k, iterm2).

I'm trying to create a simple function to dynamically update the content of MULTILINE_SECOND_PROMPT_PREFIX. Everything works as expected, except after I reload the zsh config I can type in the termial, but the moment I press the spacebar or the enter key the shell crashes. I've added a gif to show what I'm talking about, as well as the what I believe to be the relevant configuration items.

I may not be approaching the problem in the right way, or I may be missing something simple, eitherway, any help would be appreciated! Thanks!

quote () {
    export QUOTE=$1 &&
    source ~/.zshrc &&
    echo "termal quote set to " $1
}

POWERLEVEL9K_MULTILINE_SECOND_PROMPT_PREFIX="%K{white}%F{black}\n `echo $QUOTE`.%f%k%F{white}î‚°%f $ "

quotefunc

  1. Call quote function with string arg
  2. .zshrc is reloaded
  3. terminal accepts keyboard input
  4. spacebar or enter crashes terminal
question

All 11 comments

Interesting problem. I didn't try to reproduce your error, but I think re-sourcing the zshrc all the time is quite some overhead.

I would have written that function like this:

POWERLEVEL9K_PROMPT_ON_NEWLINE=true
quote () {
  POWERLEVEL9K_MULTILINE_SECOND_PROMPT_PREFIX="%K{white}%F{black}\n ${1}.%f%k%F{white}<U+E0B0>%f $ "
  echo "termal quote set to " $1
}
# Initial state
quote "."

And that way it works for me. Could you try this version?

powerleveltada

WORKS GREAT! Thanks!

Awesome! :)

I hope to turn this concept into a 'next up' todo list that reads/modifies lines from a file

$quote done <line1>
$quote new <newline>
$quote hold <line1>
$quote list
-active- "Todo2"
-hold- "Todo3"
-hold- "Todo1"

Ah. Cool. So similar to todo.txt?

orgmode files are what I had in mind, but yeah! I now see there's a powerlevel9k element for todo.txt, ;) I'll look at that code to see if anything fun can happen! Thanks!

quote-for-tw
I went with taskwarrior instead as the interface was cleaner to work with, and there's an Oh-My-Zsh completion plugin for it.

#pltask functions
## pltask is a lightweight facade to taskwarrior for use with Powerlevel9k's Last Prompt Prefix (by dmidlo @querentCode)
## Be sure to set search.case.sensitive=no within .taskrc
POWERLEVEL9K_PROMPT_ON_NEWLINE=true
POWERLEVEL9K_PROMPT_ADD_NEWLINE=true
POWERLEVEL9K_MULTILINE_FIRST_PROMPT_PREFIX="\n"

pltask () {
    setNewlinePrompt () {
        POWERLEVEL9K_MULTILINE_LAST_PROMPT_PREFIX="%K{white}%F{black}\n $1 %f%k%F{white}î‚°%f $ "
    }

    if [ -n "$3" ]; then
        echo "pltask only supports two args. did\nyou remember to use quotes when\ncreating a task?"
        return 1
    elif [ -z "$1" ]; then
        export PLTASK=`task _get 1.description`
        if [ -z "$PLTASK" ]; then
            echo "no tasks in queue, go do something else"
            echo "Setting pltask to '.' "
            setNewlinePrompt "."
        else
            echo "Setting pltask to first task from taskwarrior:" $PLTASK
            setNewlinePrompt $PLTASK
        fi
    elif [[ $1 = "_print" || $1 = "_p" ]]; then
         echo $PLTASK
    elif [[ $1 = "help" || $1 = "h" ]]; then
        echo "\n pltask is a lightweight facade to taskwarrior for use with Powerlevel9k's Last Prompt Prefix\n"
        echo   Options:
        echo -----------------------------------------------------------------------------
        echo   "  No args           ---   Calls first available task from taskwarrior."
        echo   "  help              ---   h - This help dialog."
        echo   "  list              ---   ls - A Wrapper for \'task next\'."
        echo   "  set  <taskID>     ---   s - Sets the pltask prompt to description of specified task id."
        echo   "  done              ---   d - Completes the current task and sets pltask to next task."
        echo   "  \"string\"          ---       \"string\" with no additional arguments, sets the pltask prompt but no new task."
        echo   "  \"string\" add      ---   a - \"string\" followed by 'add' will set the pltask and add a new task to taskwarrior.\n\n"
        echo   Examples:
        echo "-----------------------------------------------------------------------------\n"
        echo "   Create a task:"
        echo "      $ pltask \"Edit Super Cool Project\" add"
        echo "      $ pltask \"Write Blog Post\" a"
    elif [[ $1 = "list" || $1 = "ls" ]]; then
        task next
    elif [[ $1 = "set" || $1 = "s" ]]; then
        export PLTASK=`task _get $2.description`
        if [ -z "$PLTASK" ]; then
            export PLTASK=`task _get 1.description`
            if [ -z "$PLTASK" ]; then
                pltask
            else
                echo "no task with id $2 in queue"
                echo "Setting pltask to first available task: " $PLTASK
                setNewlinePrompt $PLTASK
            fi
        else
            echo "Setting pltask to task id $2:" $PLTASK
            setNewlinePrompt $PLTASK
        fi
    elif [[ $1 = "done" || $1 = "d" ]]; then
        task /$PLTASK/ done
        task
        export PLTASK=`task _get 1.description`
        if [ -z "$PLTASK" ]; then
                pltask
        else
            echo "Setting pltask to next task: "$PLTASK
            setNewlinePrompt $PLTASK
        fi
    elif [ -z "$2" ]; then
        setNewlinePrompt $1
        echo "terminal pltask set to " $1 "But no task has been created"
    elif [[ $2 = "add" || $2 = "a" ]]; then
        export PLTASK="$1"
        task "$1" add
        task
        setNewlinePrompt $1
    fi
}
# Initial state
pltask "."

Nice work, @dritter and @querentCode!

@querentCode - I added this to the User Segments wiki. This is really cool!

Hah! I just saw that you added it to 'Show off your config'. I copy / pasted the extra content you had there (including the link to your gist) to the User Segment page.

To get this to work, I had to change MULTILINE_SECOND_PROMPT_PREFIX to MULTILINE_LAST_PROMPT_PREFIX

@juanrgon good catch! I also found the associated issue. bhilburn expalins it in #635.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dritter picture dritter  Â·  5Comments

DanielChabrowski picture DanielChabrowski  Â·  3Comments

shibumi picture shibumi  Â·  3Comments

TheBabu picture TheBabu  Â·  5Comments

controversial picture controversial  Â·  4Comments