如何更改 tcsh 提示符以显示当前工作目录?

2024-03-10

我在用tcsh我正在寻找一种响应式工作目录,我至少想显示最后一个文件夹名称而不是获取完整路径。

想象我当前的工作目录是:

  [user@hostname/home/us/Desktop/my/projects]

然后我想显示这样的提示:

    [user@hostname projects] 

目前我正在使用.cshrc文件中的文件我是这样写的:

  alias setprompt 'set prompt="[suman@`hostname` `pwd`:~] $"'
  alias setprompt 'set prompt="${LightGreen}[${yellow}suman${Light}${LightPurple}@%m ${LightGreen}:~] ${yellow}$ ${end} "'

我也没有 PS1 变量,不知道它的作用,我想知道之间的区别.cshrc文件和.bashrc file.


您可以使用:

set prompt = '[%n@%m %c]$ '

%n对于用户名,%m对于第一个主机名., and %c对于最后一个目录部分。有大量此类替代品可用,您可以在以下位置找到它们的列表:tcsh(1),为方便起见,复制如下。

Using `pwd`不会起作用,因为cshrc文件是只读的once在 shell 启动时,而不是在每次目录更改时。

我想知道 .cshrc 文件和 .bashrc 文件之间的区别。

The cshrc文件被使用csh and tcsh, the bashrc文件被使用bash。尽管它们服务于相同的目的,但它们是不同的程序(例如~/.mozilla/firefox and ~/.config/chromium).


%/  The current working directory.
%~  The current working directory, but with one's  home  direc‐
    tory  represented  by `~' and other users' home directories
    represented  by  `~user'  as  per  Filename   substitution.
    `~user'  substitution happens only if the shell has already
    used `~user' in a pathname in the current session.
%c[[0]n], %.[[0]n]
    The trailing component of the current working directory, or
    n  trailing  components if a digit n is given.  If n begins
    with `0', the number  of  skipped  components  precede  the
    trailing  component(s)  in the format `/<skipped>trailing'.
    If the ellipsis shell variable is set,  skipped  components
    are  represented  by  an  ellipsis  so  the  whole  becomes
    `...trailing'.  `~' substitution is done as in `%~'  above,
    but  the  `~'  component  is ignored when counting trailing
    components.
%C  Like %c, but without `~' substitution.
%h, %!, !
    The current history event number.
%M  The full hostname.
%m  The hostname up to the first `.'.
%S (%s)
    Start (stop) standout mode.
%B (%b)
    Start (stop) boldfacing mode.
%U (%u)
    Start (stop) underline mode.
%t, %@
    The time of day in 12-hour AM/PM format.
%T  Like `%t', but in 24-hour format (but see  the  ampm  shell
    variable).
%p  The  `precise'  time  of  day in 12-hour AM/PM format, with
    seconds.
%P  Like `%p', but in 24-hour format (but see  the  ampm  shell
    variable).
\c  c is parsed as in bindkey.
^c  c is parsed as in bindkey.
%%  A single `%'.
%n  The user name.
%N  The effective user name.
%j  The number of jobs.
%d  The weekday in `Day' format.
%D  The day in `dd' format.
%w  The month in `Mon' format.
%W  The month in `mm' format.
%y  The year in `yy' format.
%Y  The year in `yyyy' format.
%l  The shell's tty.
%L  Clears  from the end of the prompt to end of the display or
    the end of the line.
%$  Expands the shell or environment variable name  immediately
    after the `$'.
%#  `>'  (or the first character of the promptchars shell vari‐
    able) for normal users, `#' (or  the  second  character  of
    promptchars) for the superuser.
%{string%}
    Includes string as a literal escape sequence.  It should be
    used only to change terminal attributes and should not move
    the  cursor  location.  This cannot be the last sequence in
    prompt.
%?  The return code of the command  executed  just  before  the
    prompt.
%R  In prompt2, the status of the parser.  In prompt3, the cor‐
    rected string.  In history, the history string.

`%B', `%S', `%U' and `%{string%}' are available in only  eight-
bit-clean shells; see the version shell variable.

The  bold,  standout  and underline sequences are often used to
distinguish a superuser shell.  For example,

    > set prompt = "%m [%h] %B[%@]%b [%/] you rang? "
    tut [37] [2:54pm] [/usr/accts/sys] you rang? _

If `%t', `%@', `%T', `%p', or `%P' is used, and noding  is  not
set,  then print `DING!' on the change of hour (i.e, `:00' min‐
utes) instead of the actual time.

Set by default to `%# ' in interactive shells.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何更改 tcsh 提示符以显示当前工作目录? 的相关文章

  • OS + Linux Shell bash / sh / ksh / csh / tcsh / adb shell

    s Android adb shell ADB Android debug bridge Android手机实际是基于Linux系统的 Google提供的ADB工具包带有fastboot exe rar http dl iteye com
  • $?VAR 在 csh 中意味着什么?

    我遇到过用 csh 编写的这段代码 if LM LICENSE FILE then setenv LM LICENSE FILE LmLicense else switch LM LICENSE FILE case LmLicense br
  • 在 shell 脚本运行时编辑它

    您可以在 shell 脚本运行时对其进行编辑并使更改影响正在运行的脚本吗 我很好奇 csh 脚本的具体情况 我让该批处理运行一堆不同的构建风格并运行整夜 如果我在操作过程中发生了一些事情 我想进去添加额外的命令 或者注释掉未执行的命令 如果
  • 为 Git 存储库自定义 CSH 提示

    当我在 Git 存储库中时 我希望有一个自定义 CSH 提示 如果我不在 git 存储库中 我希望提示符看起来像这样 host name gt 但是当我进入 Git 存储库时必须变成这样 host name GIT REPO ROOT DI
  • csh 上的自连接字符串

    我需要将 argv 中的部分内容连接到我的变量之一 我将向您展示我的代码 bin csh set stringList foreach param argv if param TEST then set stringList stringL
  • 如何在 sed 中将一个路径替换为另一个路径? [复制]

    这个问题在这里已经有答案了 我有一个 csh 脚本 尽管我可以更改语言 如果它有任何相关性 我必须 sed s AAA BBB file 问题在于 AAA 和 BBB 是路径 因此包含 AAA 是固定的 所以我可以说 sed s A A A
  • 如何找到我正在执行的 tcsh shell 脚本的位置?

    假设我将可执行 tcsh 文件放入 path to my script csh 我当前的目录在任何地方 例如我在 path 所以我输入 to my script csh 我想在 my script csh 中有一行返回 path to my
  • 如何将 key ctrl-left 绑定到 word-left?

    我使用 tcsh 和 emacs 在 emacs 中 我习惯使用 ctrl left 绑定键将我向左移动一个单词 我想在我的 tcsh 终端中做同样的事情 我可以按 ctrl b 但我只是不习惯 从bindkey manpath中我不清楚如
  • Unix tcsh - 使用命令行参数 $1 与 \!:1 的别名

    在 Unix tcsh 中 我使用两种不同的符号在别名中引用了命令行参数 1 and 1 但我注意到如果我尝试保存 1到环境变量 它不会被保存 然而 1确实得救了 alias hear setenv x 1 echo x gt hear t
  • TAB 自动完成 python CLI

    我只是想知道是否可以编写一个在 shell 中运行的 Python 脚本 当用户点击 Tab 时可以向他们提供建议 例如 某些应用程序如何限制其支持的建议文件类型 我在 optParse 中没有找到任何可以做到这一点的东西 理想情况下是 m
  • tcsh 脚本不退出

    我正在运行 CentOS 7 并且 tcsh 脚本出现问题 我有一个名为 quittest 的简单脚本 bin tcsh echo Simple Test exit 0 当我从终端运行 quittest 时 我得到 Simple Test
  • 让 ssh 在目标机器上后台执行命令

    这是一个后续问题如何在 shell 脚本中使用 ssh https stackoverflow com questions 29061 how do you use ssh in a shell script问题 如果我想在远程机器上执行在
  • 如何从两个列表中删除一个列表中的目录?

    我正在编写一个 c shell 脚本 其中我正在两个字符串中 grep 两个不同的目录 我想删除相同目录的名称 我只想要两个目录中唯一的目录 而忽略重复的目录 我对如何做到这一点有点困惑 sta views 和 pnr views 字符串中
  • 优雅地停止 Docker 容器

    我无法理解当容器停止时如何进行一些清理 为了方便起见 我准备了一个示例来重现该问题 以下是我的文件的内容 Dockerfile FROM opensuse latest Install tcsh non interactive mode R
  • 找到 PATTERN 时合并两个文本文件的行

    我正在寻找一个 awk 或 sed 解决方案来根据匹配的模式组合 2 个文件 如下所示 本例中的模式是 cat 文件 2 中的行数始终等于文件 1 中的模式匹配数 File 1 I am a cat I am a dog I am a do
  • 如何更改 tcsh 提示符以显示当前工作目录?

    我在用tcsh我正在寻找一种响应式工作目录 我至少想显示最后一个文件夹名称而不是获取完整路径 想象我当前的工作目录是 user hostname home us Desktop my projects 然后我想显示这样的提示 user ho
  • 在 TCSH Shell 中启用历史记录

    如何启用在 tcsh shell 中输入的所有命令的日志记录 我试过了 将 history 变量设置为 100 savehist 到 99 将 histfile 设置为 home history 在 shell 中键入命令不会将命令保存在历
  • 如何从 shell 脚本启动编辑器?

    我希望我的 tcsh 脚本启动一个编辑器 例如 vi emacs bin tcsh vi my file 这将使用 my file 启动 vi 但首先显示警告 Vim 警告 输出不是到终端 并且我的击键不会出现在屏幕上 在我杀死 vi 后
  • 最少输入命令行计算器 - tcsh 与 bash

    我喜欢有一个方便的命令行计算器 要求是 支持所有基本算术运算符 用于求幂 加上括号用于分组 需要最少的输入 我不想调用一个程序与之交互 然后要求它退出 理想情况下 除了表达式本身之外 命令行中只应输入一个字符和一个空格 它应该知道如何忽略逗
  • 为什么 rm 不能按我的预期工作?

    我只想做一件简单的事 我在目录中得到了以下文件 AppInterface h baa PEMsg h PluginInterface h 然后我发出命令 ls grep v h rm rf 令我非常沮丧的是 baa不会被删除 但是这个 ls

随机推荐

  • 在html文件Flutter中使用js文件

    如何在 Flutter 中使用与 html 关联的 js 文件 我使用 webview flutter 插件加载index html文件并且它可以工作 但是我无法加载js文件 这是我的颤振代码 return Scaffold appBar
  • 配置 Node Express 来服务静态 Bower_Components?

    我有一个目录结构 projectName bower components public css js index html Gruntfile js package json bower json app js 我想启动我的应用程序并提供
  • Mercurial 版本控制显示推送错误

    我正在为我的项目使用 Mercurial 版本控制 一切都像push pull update做得不错 但有一件事出了问题 当我使用push它显示的是这样的东西 warning bitbucket org certificate with f
  • 在javascript中将一个对象转换为多个对象[关闭]

    Closed 这个问题需要细节或清晰度 help closed questions 目前不接受答案 我想在 JavaScript 中将一个对象转换为多个对象 这是我的对象 const obj jQuery sts create form s
  • Umbraco:列出用户控件中的子节点

    我有一个用户控件 需要根据parentID 返回子节点 我能够获取parentID 但不知道返回子节点的语法 获取子节点非常简单 不确定您的代码有多远 所以这里是一个包含各种选项的完整示例 using umbraco presentatio
  • 链接多个共享库,这些共享库全部链接到一个公共静态库

    假设您有 2 个共享库 lib1 so 和 lib2 so 它们都静态链接了 libcommon a 如果要动态链接 lib1 so 和 lib2 so 编译器会抱怨符号引用不明确吗 或者编译器是否足够聪明 知道 libcommon 符号在
  • 存储过程、MySQL 和 PHP

    这是一个相当开放的问题 我已经在 MS SQLServer 中使用存储过程以及经典 ASP 和 ASP net 一段时间了 并且非常喜欢它们 我正在从事一个小型爱好项目 由于各种原因 我选择了 LAMP 路线 有什么提示 技巧 陷阱或良好的
  • 例如,C++0x auto 关键字的含义是什么?

    auto a Foo
  • 将320x240x3点云矩阵转换为320x240x1深度图

    有人可以用Python帮我解决以下问题吗 我有从虚拟相机获得的点云矩阵 其尺寸为 320x240x3 表示每个点 相机视图中的点 的 x y z 坐标 所有值的范围都从负到正 如何将此点云矩阵转换为存储每个像素的正深度值的 320x240x
  • 在 Swift 3 中使用选择器

    我正在用 Swift 3 编写我的 iOS 应用程序 我有一个UIViewController扩展 我必须检查控制器实例是否响应方法 下面是我尝试的代码 extension UIViewController func myMethod if
  • 如何使用 WorkManager 更改定期工作请求周期而不立即运行?

    val request PeriodicWorkRequestBuilder
  • 使用R的lm(),公式对象应该作为字符传递?

    我发现 R 使用 lm 时有一个奇怪的行为 基于cars对象 以下函数是在速度 30 时使用局部线性回归绘制拟合断裂距离 func1 lt function fm spd w lt dnorm cars speed spd sd 5 fit
  • Jenkins 与 intellij 共享库

    我开始实现 Jenkins 共享库并尝试使用 intellij 作为我的 ide 编写我的 jenkinsfile 如何从共享 lib 存储库获取函数到其中包含 jenkins 文件的其他存储库 只是为了澄清从 jenkins 运行时对我有
  • 查找数组的第一个重复项

    我决定学习 python 并使用 CodeFight 进行训练 第一个面试练习是找到数组的第一个重复项并返回它 如果没有则返回 1 这是我写的代码 def firstDuplicate a b print len a for i in ra
  • 当两个命令都存在时,在 jupyter 中使用“%”比使用“!”有优势吗?

    例如当我使用 pip install VSCode 建议我使用 pip install 同样有一个版本mv对彼此而言 and 使用其中一种比另一种有优势吗 Yes pip在大多数边缘情况下 将正确解析适当的虚拟环境 当前内核使用的虚拟环境
  • 如何在 Spring WebClient 中一次设置多个标头?

    我试图为我的其余客户端设置标头 但每次我都必须写 webclient get uri blah blah header key1 value1 header key2 value2 如何使用 headers 方法同时设置所有标头 如果这些标
  • Cloudinary api - 解决承诺

    我想编写一个函数 返回一个布尔值 指示我的 Cloudinary 空间中是否已存在具有指定 public id 的图像 我可以使用以下代码将结果记录到控制台 function isUploaded public id cloudinary
  • 不可能的布局?

    我开始认为这是不可能的 但我想我会问你们 基本上它是一个 2 列布局 但 业务 需要以下内容 始终占据整个浏览器窗口 适应浏览器窗口大小的调整 左栏的宽度是固定的 但该宽度在不同页面上应该是灵活的 左列顶部有一个固定高度的区域 左栏有一个底
  • 所有 mysql 引擎之间的主要区别是什么?

    我想总结一下所有 Mysql 引擎之间的主要区别 当然也包括最流行的引擎 我应该使用什么标准来确定使用哪个引擎 这里对它们进行了很好的描述 http dev mysql com doc refman 5 0 en storage engin
  • 如何更改 tcsh 提示符以显示当前工作目录?

    我在用tcsh我正在寻找一种响应式工作目录 我至少想显示最后一个文件夹名称而不是获取完整路径 想象我当前的工作目录是 user hostname home us Desktop my projects 然后我想显示这样的提示 user ho