简体   繁体   English

如何仅在第一次打开konsole时运行指定的.bashrc代码

[英]How to run a specif .bashrc code only the first time konsole is opened

I have a chunk of code in my .bashrc, everytime one runs the shell (I usually use konsole) a switch case appears giving options of which branch or trunk to use. 我的.bashrc中有很多代码,每次运行shell(我通常使用konsole)时,都会出现一个开关盒,提供使用哪个分支或主干的选项。 Example: 例:

1) V0230
2) V0300
3) Dev

Enter Option: __

$PROJECT_HOME and others variables are set upon the choise made. $ PROJECT_HOME和其他变量根据选择来设置。

The annoying thing in this is that it appears everytime I open a new tab the same screen is printed. 令人讨厌的是,每次我打开一个新选项卡时,它都会出现在同一屏幕上。 But yet I want to open a new konsole and use a different branch, so, simple export a variabe can not be the solution 但是,我想打开一个新的Konsole并使用其他分支,因此,简单地导出variabe并不是解决方案

Must have a way to run this code only when a konsole new screen is open. 必须有一种方法仅在打开konsole新屏幕时运行此代码。 Maybe making alias konsole=konsole --run <desired-function> . 也许使用alias konsole=konsole --run <desired-function> The konsole's documentation doesn't give a help, theres not even a man konsole just konsole --help . konsole的文档没有提供帮助,甚至没有man konsole只是konsole --help

Just create an alias: 只需创建一个别名:

$ alias konsole_select_branch='SELECT_BRANCH=true konsole'

and in your .bashrc : 并在您的.bashrc

if [ -n "$SELECT_BRANCH" ]
then
   # select branch
fi

and use konsole or konsole_select_branch whether you want to choose a branch or just open a tab or window. 并使用konsole或konsole_select_branch来选择分支还是只打开选项卡或窗口。

You could put a script in .bashrc which partly overwrite .bashrc ; 您可以将脚本放入.bashrc ,该脚本会部分覆盖.bashrc the zsh autocompletion facility does something similar, eg maybe do something like zsh自动完成功能可以执行类似的操作,例如,可以执行以下操作

 if [ -f $HOME/.somebashthing; ]; then
    . $HOME/.somebashthing
 else
    read SOMETHING
    echo SOMEVAR=$SOMETHING > $HOME/.somebashthing
 fi

This is only a sketch; 这只是一个草图。 it is up to you to fill the details. 您可以自行填写详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM