From c969966162494a1000b0ead5d3f87bf5d82ec0c7 Mon Sep 17 00:00:00 2001 From: sawka Date: Wed, 12 Apr 2023 14:48:10 -0700 Subject: [PATCH] updates for showing git branch and venv in prompt -- also for webshare --- src/linecomps.tsx | 4 ++-- src/sh2.less | 9 ++++++++- src/webshare-elems.tsx | 34 ++++++++++++++++++++++++++++------ 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/linecomps.tsx b/src/linecomps.tsx index 356d72d8..e69e69a4 100644 --- a/src/linecomps.tsx +++ b/src/linecomps.tsx @@ -633,8 +633,8 @@ class Prompt extends React.Component<{rptr : RemotePtrType, festate : Record{cwd}); - let remoteElem = ([{remoteStr}]); + let cwdElem = ({cwd}); + let remoteElem = ([{remoteStr}] ); let rootIndicatorElem = ({isRoot ? "#" : "$"}); let branchElem = null; let pythonElem = null; diff --git a/src/sh2.less b/src/sh2.less index f4e80d3f..d3fc4fb2 100644 --- a/src/sh2.less +++ b/src/sh2.less @@ -2353,8 +2353,9 @@ input[type=checkbox] { } #main .term-prompt { + font-size: 14px; + i { - font-size: 12px; margin-right: 3px; } @@ -2366,6 +2367,12 @@ input[type=checkbox] { color: @term-bright-magenta; } + .term-prompt-remote { + i { + margin-right: 0; + } + } + .term-prompt-remote { color: @term-bright-green; diff --git a/src/webshare-elems.tsx b/src/webshare-elems.tsx index bb6bc7df..389790d6 100644 --- a/src/webshare-elems.tsx +++ b/src/webshare-elems.tsx @@ -39,6 +39,17 @@ function makeFullRemoteRef(ownerName : string, remoteRef : string, name : string return ownerName + ":" + remoteRef + ":" + name; } +function getShortVEnv(venvDir : string) : string { + if (isBlank(venvDir)) { + return ""; + } + let lastSlash = venvDir.lastIndexOf("/"); + if (lastSlash == -1) { + return venvDir; + } + return venvDir.substr(lastSlash+1); +} + function replaceHomePath(path : string, homeDir : string) : string { if (path == homeDir) { return "~"; @@ -49,7 +60,7 @@ function replaceHomePath(path : string, homeDir : string) : string { return path; } -function getCwdStr(remote : T.WebRemote, state : T.FeStateType) : string { +function getCwdStr(remote : T.WebRemote, state : Record) : string { if (state == null || isBlank(state.cwd)) { return "~"; } @@ -70,22 +81,33 @@ function getRemoteStr(remote : T.WebRemote) : string { } @mobxReact.observer -class Prompt extends React.Component<{remote : T.WebRemote, festate : T.FeStateType}, {}> { +class Prompt extends React.Component<{remote : T.WebRemote, festate : Record}, {}> { render() { let {remote, festate} = this.props; let remoteStr = getRemoteStr(remote); let cwd = getCwdStr(remote, festate); let isRoot = !!remote.isroot; let remoteColorClass = (isRoot ? "color-red" : "color-green"); - // if (remote && remote.remoteopts && remote.remoteopts.color) { - // remoteColorClass = "color-" + remote.remoteopts.color; - // } let remoteTitle : string = null; if (remote && remote.canonicalname) { remoteTitle = remote.canonicalname; } + let cwdElem = ({cwd}); + let remoteElem = ([{remoteStr}] ); + let rootIndicatorElem = ({isRoot ? "#" : "$"}); + let branchElem = null; + let pythonElem = null; + if (!isBlank(festate["PROMPTVAR_GITBRANCH"])) { + let branchName = festate["PROMPTVAR_GITBRANCH"]; + branchElem = ({branchName} ); + } + if (!isBlank(festate["VIRTUAL_ENV"])) { + let venvDir = festate["VIRTUAL_ENV"]; + let venv = getShortVEnv(venvDir); + pythonElem = ({venv} ); + } return ( - [{remoteStr}] {cwd} {isRoot ? "#" : "$"} + {remoteElem} {pythonElem}{branchElem}{cwdElem} {rootIndicatorElem} ); } }