LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   zle widget printing blank line before the next prompt (https://www.linuxquestions.org/questions/linux-newbie-8/zle-widget-printing-blank-line-before-the-next-prompt-4175679442/)

blueray 07-27-2020 12:02 AM

zle widget printing blank line before the next prompt
 
I am using the following widget so that I do not have to write git clone to clone a repo.

Code:

function _accept-line-with-url {

    if  [[ $BUFFER =~ ^https.*git ]]
    then
        printf "\n"
        git clone $BUFFER && cd "$(basename $BUFFER .git)"

        zle kill-whole-line
        zle .accept-line
    else
        zle .accept-line
    fi
}

zle -N accept-line _accept-line-with-url

However, it has a small problem.

Code:

~/Desktop% https://github.com/chmln/sd.git
Cloning into 'sd'...
remote: Enumerating objects: 78, done.
remote: Counting objects: 100% (78/78), done.
remote: Compressing objects: 100% (57/57), done.
remote: Total 792 (delta 34), reused 48 (delta 15), pack-reused 714
Receiving objects: 100% (792/792), 239.98 KiB | 308.00 KiB/s, done.
Resolving deltas: 100% (456/456), done.
                             
Desktop/sd:master=%

If you look at Desktop/sd:master=% , It is printing an extra blank line before this prompt. Why is that blank line there? How can I remove it?

blueray 07-27-2020 12:48 AM

OP here, The solution that is working for me is

Code:

function _accept-line-with-url {

    if  [[ $BUFFER =~ ^https.*git ]]
    then

        echo $BUFFER >> $HISTFILE
        fc -R

        BUFFERz="git clone $BUFFER && cd $(basename $BUFFER .git)"
        zle .kill-whole-line
        BUFFER=$BUFFERz
        zle .accept-line
    else
        zle .accept-line
    fi
}

zle -N accept-line _accept-line-with-url



All times are GMT -5. The time now is 12:28 AM.