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

#!/bin/bash

# cf. Creating password prompts using Bash, http://ubuntuforums.org/showthread.php?t=269592

stty_orig=$(stty -g) 

# Init some stuff...
pass=''
blank='false'

# 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
      blank='true'
   else
      stty echo
      echo -n "*"
      pass="$pass$c"
      stty -echo
   fi
done

stty icanon echo

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
Start->Run->regedit
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" ]
then
        if [ `/usr/bin/whoami` = 'root' ]
        then
                export PS1='\[\033[01;31m\]\h \[\033[01;34m\]\W \$ \[\033[00m\]'
        else
                export PS1='\[\033[01;32m\]\u@\h \[\033[01;34m\]\W \$ \[\033[00m\]'
        fi
fi

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