Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

« Newer Snippets
Older Snippets »
3 total  XML / RSS feed 

Bash password prompt


# cf. Creating password prompts using Bash,

stty_orig=$(stty -g) 

# Init some stuff...

# Main loop executed once for each char typed...
while [[ "$blank" != "true" ]]; do
   stty -icanon -echo
   c=$(dd bs=6 count=1 2> /dev/null)

   # Check for a CR.
   if [ -z "$(echo "$c" | tr -d "\r\n")" ]; then
      stty echo
      echo -n "*"
      stty -echo

stty icanon echo

echo "$pass"

stty "$stty_orig"

exit 0

Windows' command prompt : How to DEFINITELY change default codepage

Want to use WinLatin1 (1252) instead of DOSLatin1 (850, default when cmd.exe is started) ?

You want to apply the new codepage to :
- the current opened command prompt
C:\> chcp 1252

- all the opened command prompt in the future
Go to [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Nls\CodePage]
And change the "OEMCP" value to "1252"

You need to restart your computer to see the changes.

So you'll be able to display extended characters (such as accents and so on)


Don't know how to check the command prompt's codepage ?
C:\> chcp


Want to see the result in practice ?
Edit a codepage.txt file and type "à la bonne heure, ça marche ! (peut être)", then open a command prompt and check this out :
C:\> type codepage.txt

Pretty PS1 Prompt for Bash

This is just a simple colored bash prompt which differentiates nicely between normal and root users.

To use this put it in ~/.bashrc, or for it to apply systemwide, in /etc/profile

if [ "$TERM" != 'dumb' ] && [ -n "$BASH" ] && [ -n "$PS1" ]
        if [ `/usr/bin/whoami` = 'root' ]
                export PS1='\[\033[01;31m\]\h \[\033[01;34m\]\W \$ \[\033[00m\]'
                export PS1='\[\033[01;32m\]\u@\h \[\033[01;34m\]\W \$ \[\033[00m\]'

Updated: It's now more concise and functionally more sensible.
« Newer Snippets
Older Snippets »
3 total  XML / RSS feed