#7 `subbash/prompt`: Any reason for adding `[` and `]` to GBranch var instead of PS1?

已关闭
tukusejssirs6 年之前创建 · 3 条评论

I’ve just noticed that in the latest commit you moved the square brackets ([]) around GBranch from PS1 variable to GBranch variable itself. Any reason for this change?

This change caused more characters to be added (4 pairs instead of one).

I’ve just noticed that in the [latest commit](https://notabug.org/demure/dotfiles/commit/9fb5acac2685b4c337f76613333f6873d9aebb99) you moved the square brackets (`[]`) around `GBranch` from PS1 variable to `GBranch` variable itself. Any reason for this change? This change caused more characters to be added (4 pairs instead of one).
demure 评论于 6 年之前
所有者

This change was to facilitate marking a detached head state with ()'s without being surrounded by square brackets. ie [(12345678)] At the time, this seemed like the most succinct way to handle the logic as the alternative would have been to build another another Test after 'Find Branch' code section with a if/else tree of different PS1+= lines.

If you believe that the current way creates less sanitary code I can consider switching over. It was mostly an on-the-fly lines of code saving decision.

This change was to facilitate marking a detached head state with `()`'s without being surrounded by square brackets. ie `[(12345678)]` At the time, this seemed like the most succinct way to handle the logic as the alternative would have been to build another another Test after 'Find Branch' code section with a if/else tree of different `PS1+=` lines. If you believe that the current way creates less sanitary code I can consider switching over. It was mostly an on-the-fly lines of code saving decision.
tukusejssirs 评论于 6 年之前
发布者

Oh, I forgot about that. I think it is better to have a few more characters in comparison with additional if statement.

However, you should probably put the square brackets around ERROR, too:

                if [ -n "${GBranch}" ]; then
                    GBranch="[${GBranch}]"              ## Add brackets for final output. Will now test against brackets as well.
                    if [ "${GBranch}" == "[master]" ]; then
                        local GBranch="[M]"             ## Because why waste space
                    fi
                    ## Test if in detached head state, and set output to first 8char of hash
                    if [ "${GBranch}" == "[(detached)]" ]; then
                        GBranch="($(echo ${GStatus} | awk 'match($0,/branch.oid [0-9a-fA-F]+/) {print substr($0,RSTART+11,RLENGTH-11)}' | cut -c1-8))"
                    fi
                  else
                    local GBranch="ERROR"               ## It could happen?
                fi

PS—From English point of view, you should change It could happen? to Could it even happen?, though it is not important at all from the code point of view. :)

Oh, I forgot about that. I think it is better to have a few more characters in comparison with additional `if` statement. However, you should probably put the square brackets around `ERROR`, too: ```bash if [ -n "${GBranch}" ]; then GBranch="[${GBranch}]" ## Add brackets for final output. Will now test against brackets as well. if [ "${GBranch}" == "[master]" ]; then local GBranch="[M]" ## Because why waste space fi ## Test if in detached head state, and set output to first 8char of hash if [ "${GBranch}" == "[(detached)]" ]; then GBranch="($(echo ${GStatus} | awk 'match($0,/branch.oid [0-9a-fA-F]+/) {print substr($0,RSTART+11,RLENGTH-11)}' | cut -c1-8))" fi else local GBranch="ERROR" ## It could happen? fi ``` PS—From English point of view, you should change `It could happen?` to `Could it even happen?`, though it is not important at all from the code point of view. :)
demure 评论于 6 年之前
所有者

I was thinking (though I could certainly add a comment explaining this rational) that a PS1 with ERROR would help emphasize that an Issue existed and de-conflict with the chance of a branch named 'ERROR' (which would show up in the PS1 as [ERROR].

I was thinking (though I could certainly add a comment explaining this rational) that a PS1 with `ERROR` would help emphasize that an Issue existed and de-conflict with the chance of a branch named 'ERROR' (which would show up in the PS1 as `[ERROR]`.
demure6 年之前 关闭
登录 并参与到对话中。
未选择标签
bug
未选择里程碑
未指派成员
2 名参与者
正在加载...
取消
保存
这个人很懒,什么都没留下。