mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-22 09:41:07 +00:00
Fix setting $PS1 for bash
And let user know how to set prompt for zsh and powerline in our README.
This commit is contained in:
parent
33e0791294
commit
0b3ba49c6c
2 changed files with 43 additions and 15 deletions
29
README.md
29
README.md
|
@ -40,3 +40,32 @@ If your operating system handles symlinks, built modules source code will be ava
|
||||||
at the root of `gst-build/` for example GStreamer core will be in `gstreamer/`. Otherwise
|
at the root of `gst-build/` for example GStreamer core will be in `gstreamer/`. Otherwise
|
||||||
they will be present in `subprojects/`. You can simply hack in there and to rebuild you
|
they will be present in `subprojects/`. You can simply hack in there and to rebuild you
|
||||||
just need to rerun `ninja -C build/`.
|
just need to rerun `ninja -C build/`.
|
||||||
|
|
||||||
|
|
||||||
|
## Add information about GStreamer development environment in your prompt line
|
||||||
|
|
||||||
|
### Bash prompt
|
||||||
|
|
||||||
|
We automatically handle `bash` and set `$PS1` accordingly
|
||||||
|
|
||||||
|
### Zsh prompt
|
||||||
|
|
||||||
|
In your `.zshrc`, you should add something like:
|
||||||
|
|
||||||
|
```
|
||||||
|
export PROMPT="$GST_ENV-$PROMPT"
|
||||||
|
```
|
||||||
|
|
||||||
|
### Using powerline
|
||||||
|
|
||||||
|
In your powerline theme configuration file (by default in
|
||||||
|
`{POWERLINE INSTALLATION DIR}/config_files/themes/shell/default.json`)
|
||||||
|
you should add a new environment segment as follow:
|
||||||
|
|
||||||
|
```
|
||||||
|
{
|
||||||
|
"function": "powerline.segments.common.env.environment",
|
||||||
|
"args": { "variable": "GST_ENV" },
|
||||||
|
"priority": 50
|
||||||
|
},
|
||||||
|
```
|
||||||
|
|
|
@ -4,7 +4,9 @@ import argparse
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import site
|
import site
|
||||||
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import tempfile
|
||||||
|
|
||||||
|
|
||||||
SCRIPTDIR = os.path.abspath(os.path.dirname(__file__))
|
SCRIPTDIR = os.path.abspath(os.path.dirname(__file__))
|
||||||
|
@ -15,16 +17,6 @@ def prepend_env_var(env, var, value):
|
||||||
env[var] = env[var].replace(os.pathsep + os.pathsep, os.pathsep).strip(os.pathsep)
|
env[var] = env[var].replace(os.pathsep + os.pathsep, os.pathsep).strip(os.pathsep)
|
||||||
|
|
||||||
|
|
||||||
def set_prompt_var(options, env):
|
|
||||||
ps1 = env.get("PS1")
|
|
||||||
if ps1:
|
|
||||||
env["PS1"] = "[gst-%s] %s" % (options.gst_version, ps1)
|
|
||||||
|
|
||||||
prompt = env.get("PROMPT")
|
|
||||||
if prompt:
|
|
||||||
env["PROMPT"] = "[gst-%s] %s" % (options.gst_version, prompt)
|
|
||||||
|
|
||||||
|
|
||||||
def get_subprocess_env(options):
|
def get_subprocess_env(options):
|
||||||
env = os.environ.copy()
|
env = os.environ.copy()
|
||||||
|
|
||||||
|
@ -56,6 +48,7 @@ def get_subprocess_env(options):
|
||||||
prepend_env_var(env, "PATH", os.path.join(SCRIPTDIR, 'meson'))
|
prepend_env_var(env, "PATH", os.path.join(SCRIPTDIR, 'meson'))
|
||||||
env["PATH"] += os.pathsep + PATH
|
env["PATH"] += os.pathsep + PATH
|
||||||
env["GST_VERSION"] = options.gst_version
|
env["GST_VERSION"] = options.gst_version
|
||||||
|
env["GST_ENV"] = 'gst-' + options.gst_version
|
||||||
env["GST_PLUGIN_SYSTEM_PATH"] = ""
|
env["GST_PLUGIN_SYSTEM_PATH"] = ""
|
||||||
env["GST_PLUGIN_SCANNER"] = os.path.normpath(
|
env["GST_PLUGIN_SCANNER"] = os.path.normpath(
|
||||||
"%s/subprojects/gstreamer/libs/gst/helpers/gst-plugin-scanner" % options.builddir)
|
"%s/subprojects/gstreamer/libs/gst/helpers/gst-plugin-scanner" % options.builddir)
|
||||||
|
@ -89,9 +82,6 @@ def get_subprocess_env(options):
|
||||||
if has_typelib:
|
if has_typelib:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
set_prompt_var(options, env)
|
|
||||||
|
|
||||||
return env
|
return env
|
||||||
|
|
||||||
|
|
||||||
|
@ -115,8 +105,17 @@ if __name__ == "__main__":
|
||||||
args = [os.environ.get("COMSPEC", r"C:\WINDOWS\system32\cmd.exe")]
|
args = [os.environ.get("COMSPEC", r"C:\WINDOWS\system32\cmd.exe")]
|
||||||
else:
|
else:
|
||||||
args = [os.environ.get("SHELL", os.path.realpath("/bin/sh"))]
|
args = [os.environ.get("SHELL", os.path.realpath("/bin/sh"))]
|
||||||
if args[0] == "/bin/bash":
|
if "bash" in args[0]:
|
||||||
args.append("--noprofile")
|
bashrc = os.path.expanduser('~/.bashrc')
|
||||||
|
if os.path.exists(bashrc):
|
||||||
|
tmprc = tempfile.NamedTemporaryFile(mode='w')
|
||||||
|
with open(bashrc, 'r') as src:
|
||||||
|
shutil.copyfileobj(src, tmprc)
|
||||||
|
tmprc.write('\nexport PS1="[gst-%s] $PS1"' % options.gst_version)
|
||||||
|
tmprc.flush()
|
||||||
|
# Let the GC remove the tmp file
|
||||||
|
args.append("--rcfile")
|
||||||
|
args.append(tmprc.name)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
exit(subprocess.call(args, env=get_subprocess_env(options)))
|
exit(subprocess.call(args, env=get_subprocess_env(options)))
|
||||||
|
|
Loading…
Reference in a new issue