ps1

ubuntu命令行不显示绝对路径

柔情痞子 提交于 2019-12-06 14:16:24
需要编辑文档 “~/.bashrc” 即可: 1 txx@txx:precomp$ vim ~/.bashrc 2 3 4 if [ "$color_prompt" = yes ]; then 5 PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' 6 else 7 PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' 8 fi ​将两个小写的'w',改成大写的'w'即可; 保存后退出编辑器, 再执行命令 ​$ source ~/.bashrc 1 txx@txx:~/sl/code/rulescanengine/precomp$ source ~/.bashrc 2 txx@txx:precomp$ ls 来源: https://www.cnblogs.com/alog9/p/11988945.html

How can I properly use two-character-width emoji in my bash prompt?

£可爱£侵袭症+ 提交于 2019-12-06 12:08:47
问题 I want to use an American flag emoji in my bash prompt (i.e. PS1 environment variable). However, the American flag emoji causes the terminal cursor to offset an extra character to the right. 🇺🇸 is comprised of two unicode characters, 🇺 and 🇸. I believe terminal is converting this to a mono-spaced emoji character (the flag), yet still allocating space for two characters. How can I achieve my expected cursor position? I want: 🇺🇸 Desktop akirna 🗽 ls| I get: 🇺🇸 Desktop akirna 🗽 ls | << weird

Bash printf %q invalid directive

时光总嘲笑我的痴心妄想 提交于 2019-12-06 06:05:57
问题 I want to change my PS1 in my .bashrc file. I've found a script using printf with %q directive to escape characters : #!/bin/bash STR=$(printf "%q" "PS1=\u@\h:\w\$ ") sed -i '/PS1/c\'"$STR" ~/.bashrc The problem is that I get this error : script.sh: 2: printf: %q: invalid directive Any idea ? Maybe an other way to escape the characters ? 回答1: The printf command is built into bash. It's also an external command, typically installed in /usr/bin/printf . On most Linux systems, /usr/bin/printf is

两个任意多边形的交并面积

佐手、 提交于 2019-12-05 10:58:09
#include<bits/stdc++.h> using namespace std; #define maxn 510 const double eps=1E-8; int sig(double d){ return(d>eps)-(d<-eps); } struct Point{ double x,y; Point(){} Point(double x,double y):x(x),y(y){} bool operator==(const Point&p)const{ return sig(x-p.x)==0&&sig(y-p.y)==0; } }; double cross(Point o,Point a,Point b){ return(a.x-o.x)*(b.y-o.y)-(b.x-o.x)*(a.y-o.y); } double area(Point* ps,int n){ ps[n]=ps[0]; double res=0; for(int i=0;i<n;i++){ res+=ps[i].x*ps[i+1].y-ps[i].y*ps[i+1].x; } return res/2.0; } int lineCross(Point a,Point b,Point c,Point d,Point&p){ double s1,s2; s1=cross(a,b,c); s2

Getting a dynamic bash prompt PS1 right

本小妞迷上赌 提交于 2019-12-05 10:27:20
I'm working on a dynamic bash prompt where I want reported in PS1 which version of a config file is enabled on the local filesystem. This is a contrived example of what I'm trying to do, simplified. The things that are going wrong: bad wrapping and/or escape brackets appearing. Can anyone spot what I'm doing wrong? If the contrived config matches "v2", I want to see that version in PS1 as YELLOW. If it's "v1", in the prompt as GREEN. The setup: $ grep FOOVER foo-*.conf foo-v1.conf:# FOOVER xyz-v1 foo-v2.conf:# FOOVER zet-v2 I'd then symlink foo.conf foo-v1.conf. My bashrc: 0 GREEN=$(tput setaf

short date in bash PS1 prompt

时光总嘲笑我的痴心妄想 提交于 2019-12-04 22:20:12
You can use \d in the your PS1 confuration to display a long date ie. Tues 18 May, but how can I get it to display it in a format like 18.05.2012 for example? Try this: PS1="\$(date +%d.%m.%Y) > " export PS1 Try including \D{%d.%m.%Y} . You can use any time format suppoorted by strftime(3) . Use \D{format } where format is a strftime format code. For example: $ export PS1='\D{%d.%m.%Y}$ ' 08.02.2012$ Rather than telling the shell to execute the date command each time, you would rather use the built-in format. Hence you can also use (though a little variation from what you have asked) \D{%F %T}

How to set a conditional newline in PS1?

三世轮回 提交于 2019-12-04 17:28:22
问题 I am trying to set PS1 so that it prints out something just right after login, but preceded with a newline later. Suppose export PS1="\h:\W \u\$ " , so first time (i.e., right after login) you get: hostname:~ username$ I’ve been trying something like in my ~/.bashrc : function __ps1_newline_login { if [[ -n "${PS1_NEWLINE_LOGIN-}" ]]; then PS1_NEWLINE_LOGIN=true else printf '\n' fi } export PS1="\$(__ps1_newline_login)\h:\W \u\$ “ expecting to get: # <empty line> hostname:~ username$ A

How can I properly use two-character-width emoji in my bash prompt?

南笙酒味 提交于 2019-12-04 15:29:37
I want to use an American flag emoji in my bash prompt (i.e. PS1 environment variable). However, the American flag emoji causes the terminal cursor to offset an extra character to the right. 🇺🇸 is comprised of two unicode characters, 🇺 and 🇸. I believe terminal is converting this to a mono-spaced emoji character (the flag), yet still allocating space for two characters. How can I achieve my expected cursor position? I want: 🇺🇸 Desktop akirna 🗽 ls| I get: 🇺🇸 Desktop akirna 🗽 ls | << weird space offset before cursor My ~/.bash_profile is: export PS1='🇺🇸 \W \u 🗽 ' Updated Answer The way your are

How to set a conditional newline in PS1?

对着背影说爱祢 提交于 2019-12-03 11:35:15
I am trying to set PS1 so that it prints out something just right after login, but preceded with a newline later. Suppose export PS1="\h:\W \u\$ " , so first time (i.e., right after login) you get: hostname:~ username$ I’ve been trying something like in my ~/.bashrc : function __ps1_newline_login { if [[ -n "${PS1_NEWLINE_LOGIN-}" ]]; then PS1_NEWLINE_LOGIN=true else printf '\n' fi } export PS1="\$(__ps1_newline_login)\h:\W \u\$ “ expecting to get: # <empty line> hostname:~ username$ A complete example from the the beginning would be: hostname:~ username$ ls `# notice: no empty line desired

bash提示符

回眸只為那壹抹淺笑 提交于 2019-12-03 04:26:47
我喜欢的设定 export PS1="\[\e[32;1m\][\[\e[33;1m\]\u\[\e[31;1m\]@\[\e[33;1m\]\h \[\e[36;1m\]\w\[\e[32;1m\]]\[\e[34;1m\]$ \[\e[0m\]" 修改bash提示符 在bash中输入 PS1='\u@\H> '; export PS1 这时候shell显示提示符格式为 当前用户名、主机名 PS1='\u@\H:\w> '; export PS1 格式为 当前用户名、主机名、当前工作目录 一些能让你自定义 Bash 提示符的黑科技 当你在 Linux 环境下打开一个 Shell 终端时,会看到命令行中出现了类似下面的一个 Bash 提示符: [user@$host ~]$ 你知道命令行提示符其实是可以自己设置添加许多非常有用的信息的吗?在这篇文章中我就会教你如何自定义自己的 Bash 命令行提示符,想看的话就接着看吧~ 如何设置 Bash 提示符 Bash 提示符是通过环境变量 PS1 (提示符字符串 1Prompt String 1) 来设置的,它用于交互式 shell 提示符。当然如果你需要更多的输入才能完成一个 Bash 命令时,PS2 环境变量就是用来设置多行提示符的: [dneary@dhcp-41-137 ~]$ export PS1="[Linux Rulez]$