Pagina1 van 1
Forum

Welkom bij de Tweaking4All gemeenschapsforums!
Voor je gaat deelnemen, bekijk de Forum Regels!

Specifieke onderwerpen: Start het onderwerp met de naam van het programma of systeem.
Bijvoorbeeld “MacOS X – Jouw vraag“, of bijvoorbeeld “MS Word – Jouw Tip of Truc“.

Merk op: Omschakelen naar een andere taal zal niet werken als je een post aan het lezen bent aangezien er waarschijnlijk geen vertaling beschikbaar is.



MacOS – Hoe maak je...
 
Deel:
Meldingen
Alles wissen

[Opgelost] MacOS – Hoe maak je de Bash prompt opvallend in Terminal (bold)

1 Berichten
1 Gebruikers
0 Reactions
1,373 Bekeken
 Hans
(@hans)
Famed Member Admin
Deelgenomen: 12 jaar geleden
Berichten: 2859
Topic starter  

Soms start ik wel eens commando in Terminal die wat veel output geeft en dan wil ik nog weleens terug scrollen om naar de output te kijken. Daarvoor leek het me handig om de prompt in Terminal bold te maken zoals hieronder beschreven ...

Als voorbeeld wil ik in plaats van de volgende standaard uitvoer:

MAC_PRO:~ hans$ ls
Applications Downloads MountPoints Pictures tmp
Desktop Dropbox Movies Public
Documents Library Music

Graag het volgende zien:

MAC_PRO:~ hans$ ls
Applications Downloads MountPoints Pictures tmp
Desktop Dropbox Movies Public
Documents Library Music 

Om dit te bereiken moeten we de "PS1" environment waarde veranderen, welke standaard deze waarde heeft:

"\h:\W \u\$ "

(Onderaan nog een lijstje met andere dingen, zoals tijd enzo, die je aan de prompt kunt toevoegen)

Om de prompt bold (vetgedrukt) te maken veranderen de waarde van PS1 als volgt:

export PS1="\[\033[1m\]\h:\W \u\$\[\033[m\] "

Hier wordt vet gedrukt gestart met de code \[\033[1m\] en weer gestopt met de code \[\033[m\].
Voor de volledigheid, de andere codes:
\h = hostname, \W = basisnaam van de directory, \u = username en een spatie aan het einde.

Als je nu Terminal sluit ben je deze instelling echter weer kwijt - beetje knudde natuurlijk als we dat steeds weer moeten invoeren.
Om dit permanent te maken moet je deze export regel toevoegen aan het bestand  ~/.bash_profile  (maak het bestand met een text editor zoals "nano" om het aan te maken). De regel mag vooraan of achteraan in dit bestand geplaatst worden ... het lijkt niets uit te maken waar je het zet.

In de afbeelding hieronder ziet je het effect in actie.

Merk op: hieronder een lijst met alternatieve codes die je in de prompt kunt gebruiken:

\a         # an ASCII bell character (07)
\d # the date in "Weekday Month Date" format (e.g., "Tue May 26")
\D{format} # the format is passed to strftime(3) and the result
           # is inserted into the prompt string an empty format
           # results in a locale-specific time representation.
           # The braces are required
\e # an ASCII escape character (033)
\h # the hostname up to the first '.'
\H # the hostname
\j # the number of jobs currently managed by the shell
\l # the basename of the shell's terminal device name
\n # newline
\r # carriage return
\s # the name of the shell, the basename of $0 (the portion following
           # the final slash)
\t # the current time in 24-hour HH:MM:SS format
\T # the current time in 12-hour HH:MM:SS format
\@ # the current time in 12-hour am/pm format
\A # the current time in 24-hour HH:MM format
\u # the username of the current user
\v # the version of bash (e.g., 2.00)
\V # the release of bash, version + patch level (e.g., 2.00.0)
\w # the current working directory, with $HOME abbreviated with a tilde
\W # the basename of the current working directory, with $HOME
           # abbreviated with a tilde
\! # the history number of this command
\# # the command number of this command
\$ # if the effective UID is 0, a #, otherwise a $
\nnn # the character corresponding to the octal number nnn
\\ # a backslash
\[ # begin a sequence of non-printing characters, which could be used
           # to embed a terminal control sequence into the prompt
\] # end a sequence of non-printing characters

   
BeantwoordenCiteren
Deel: