You are Here:
Linux Lite 4.6 RC1 has been released. See the Release Announcements section for more information.



[ HELPFUL TIP ] Terminal customisations (prompt, avoiding ./ and aliasing cd ..)

Author (Read 1471 times)

0 Members and 1 Guest are viewing this topic.

 

alowe

  • New to Forums
  • *
  • 10
    Posts
  • Country: gb
  • Reputation: 2
  • Linux Lite Member

  • Linux Lite: 3.6 32bit

  • CPU: Core 2-duo 1.73MHz

  • MEMORY: 1Gb
I'd read in several places that you're not supposed to edit ~/.bashrc but when I edited ~/.profile none of the changes worked, so using .bashrc for now until someone can explain why.

Here's some lines I appended to .bashrc after 1 day using LinuxLite:

Code: [Select]
# set command prompt to Windows DOS style
PS1='$(pwd)>'

Because I don't need to know the user or the host as these will never change. Don't need to know if Terminal is opened with root access as that is obvious to the person who opened the Terminal (who is only me). Also, I don't want to see ~ as the abbreviation for the home directory as this hides information I want to know.

Code: [Select]
# set PATH so that user can avoid typing ./ before running executables
PATH=.:$PATH

Because I expect the computer to understand that when the directory isn't explicitly specified then it should default to the current working directory. That to me is just common sense.

Code: [Select]
# use / as Amiga style cd .. command. alias doesn't allow / so use function
function / { cd '..'; }

I'm so used to typing / to go to the parent directory that it's ingrained in muscle memory even after decades of not doing this. It's a minor hassle to force myself to type cd .. which seems so clunky by comparison. When I tried to set this using alias it kept throwing an error, so resorted to using function.
 


Re: Terminal customisations (prompt, avoiding ./ and aliasing cd ..)
« Reply #1 on: March 29, 2018, 05:19:02 PM »
 

bitsnpcs

  • Platinum Level Poster
  • **********
  • 3185
    Posts
  • Country: 00
  • Reputation: 300

  • Linux Lite: 3.2 64bit
You may find this interesting for navigating -

https://unix.stackexchange.com/questions/77077/how-do-i-use-pushd-and-popd-commands


To reduce retyping of long commands you can use history command like so -

Code: [Select]
history
to reduce reading of long history of commands you could just list last 3 or 10, example

Code: [Select]
history 3
would show a list of 3 numbered commands from the history file

if the command you wished to recall was numbered at its beginning example, 381, to run that long command and save retyping it you enter -

Code: [Select]
!381
It is a chapter ahead of where I am at, but I just gave it a quick try out before posting this. It seems like it would be very useful functionality.
Last Edit: March 29, 2018, 05:45:21 PM by bitsnpcs
 

Re: Terminal customisations (prompt, avoiding ./ and aliasing cd ..)
« Reply #2 on: March 30, 2018, 08:15:52 AM »
 

alowe

  • New to Forums
  • *
  • 10
    Posts
  • Country: gb
  • Reputation: 2
  • Linux Lite Member

  • Linux Lite: 3.6 32bit

  • CPU: Core 2-duo 1.73MHz

  • MEMORY: 1Gb
Just going to add these as and when I find them.

A simple alias to get rm to behave like DOS del.

Code: [Select]
alias del="rm -r"
The -r is the option added to recursively delete directory contents (as well as the directory specified). Be careful you don't accidentally delete a directory. By default rm doesn't delete directories so the -r option is added so you can use del as a delete all command.

Code: [Select]
#compile and execute a program easily
function run { gcc -o $1 $1.c; $1; }

If you're learning to program in C (like I am, for fun) then this makes things a bit quicker. It overwrites by default.

Instead of typing:
Code: [Select]
gcc -o HelloWorld Helloworld.c
./Helloworld

all you have to type is:
Code: [Select]
run HelloWorld
needs the line, PATH=.:$PATH, to be added beforehand to take advantage of avoiding ./

And a few other additions:

Code: [Select]
alias cls="clear"
alias type="cat"

I did try using less with a -FX option but it doesn't behave like I want it to. Scrolls one line at a time and only exits on ^Z. cat is fine for the job because Terminal has a vertical scroll bar. If it's bigger than 1 screen just scroll up using the mouse. No problemo!
Last Edit: March 30, 2018, 09:05:50 AM by alowe
 

Re: Terminal customisations (prompt, avoiding ./ and aliasing cd ..)
« Reply #3 on: March 30, 2018, 09:29:24 AM »
 

trinidad

  • Moderator
  • Gold Level Poster
  • *****
  • 970
    Posts
  • Country: us
  • Reputation: 174
  • Linux Lite Member
    • dbts-analytics.com

  • Linux Lite: 4.4 64bit

  • CPU: AMD A8 5500 4 cores

  • MEMORY: 8Gb

  • VIDEO CARD: AMD/ATI Radeon HD 7560D
"I'd read in several places that you're not supposed to edit ~/.bashrc but when I edited ~/.profile none of the changes worked, so using .bashrc for now until someone can explain why."

On systems like Ubuntu that are installed without a root user and root password ~/.bashrc exists in user configuration space like all ~/.rcs. It is preferable on systems that have a root user in actual root space that significant changes are kept in a profile which corresponds to a specific user because root user configurations also exist. Also for the same reasons ~ will not work with some commands involving recursive file navigation. Also some text editors must be updated as well, as some will fail with changes made to root configurations of bash. Generally, depending on the system, different default text editors exist. Not all are effective at everything on a system by system basis and may respond differently to different bash configurations.

TC
All opinions expressed and all advice given by Trinidad Cruz on this forum are his responsibility alone and do not necessarily reflect the views or methods of the developers of Linux Lite. He is a citizen of the United States where it is acceptable to occasionally be uninformed and inept as long as you pay your taxes.
 

Re: Terminal customisations (prompt, avoiding ./ and aliasing cd ..)
« Reply #4 on: June 26, 2019, 08:07:17 PM »
 

thomasd

  • New to Forums
  • *
  • 3
    Posts
  • Country: au
  • Reputation: 0
  • Linux Lite Member

  • Linux Lite: 4.4 64bit

  • CPU: VM
Setting $PS1 in LL 4.4 does not change the command prompt, I cannot change the bash prompt in any terminal.  I've tracked it through all the normal config files and changed everything I thought might have an effect, to no avail.

One suspicious thing, the definition for PS1 when you echo it is fully expanded:
Code: [Select]
 thomasd  ~  echo $PS1
\[\] thomasd \[\] \[\]~ \[\] \[\]
 thomasd  ~  

so it looks like some service somewhere is setting PS1 in the background.

Help!
 

Re: Terminal customisations (prompt, avoiding ./ and aliasing cd ..)
« Reply #5 on: June 28, 2019, 05:34:21 PM »
 

bitsnpcs

  • Platinum Level Poster
  • **********
  • 3185
    Posts
  • Country: 00
  • Reputation: 300

  • Linux Lite: 3.2 64bit
Do you have " or ' around the special characters of username ?
Having these will cause it to expand the results, such as "PWD" would, compared to PWD (according to Ubuntu).
Other than that being the cause I do not know what it can be.

There is also this - https://stackoverflow.com/questions/10060500/bash-how-to-evaluate-ps1-ps2

I haven't used this script and so would not be able to help with it if you do.
Others may be able to help though.
Also LL series 4 is using a different terminal than the series 3 I use, its methods are not covered in the Linux Command Line book, or any book I have.
 

Re: Terminal customisations (prompt, avoiding ./ and aliasing cd ..)
« Reply #6 on: June 29, 2019, 05:09:51 PM »
 

trinidad

  • Moderator
  • Gold Level Poster
  • *****
  • 970
    Posts
  • Country: us
  • Reputation: 174
  • Linux Lite Member
    • dbts-analytics.com

  • Linux Lite: 4.4 64bit

  • CPU: AMD A8 5500 4 cores

  • MEMORY: 8Gb

  • VIDEO CARD: AMD/ATI Radeon HD 7560D
No need for dual posting or for thread hi-jacking. Your question was ill-defined and should have been in a new thread.The answer to your question the way you asked it is simple: You can customize the bash prompt on any installed Linux/Unix system, but I'm not clear on on whether or not you're attempting this on a live ISO. A virtualized live ISO is not an installed system.

TC
All opinions expressed and all advice given by Trinidad Cruz on this forum are his responsibility alone and do not necessarily reflect the views or methods of the developers of Linux Lite. He is a citizen of the United States where it is acceptable to occasionally be uninformed and inept as long as you pay your taxes.
 


Tags:
 


Linux Lite 4.6 RC1 has been released. See the Release Announcements section for more information.