Make sure all non-printable bytes in your PS1 are contained within \[ \]
. Otherwise, bash will count them in the length of the prompt. It uses the length of the prompt to determine when to wrap the line.
For example, here bash counts the prompt as 19 columns wide, while the prompt displayed by the terminal is only 10 columns wide (My prompt
written in cyan, and >
written in default color):
PS1='\e[36mMy prompt\e[0m>' # bash count: 19, actual: 10
while here it only counts the prompt as 10 columns wide because it ignores the bytes between the special \[
and \]
escapes:
PS1='\[\e[36m\]My prompt\[\e[0m\]>' # bash count: 10, actual: 10
For good practice though, use tput
to generate the terminal escapes rather than hard coding them:
cyan=$(tput setaf 6) # \e[36m
reset=$(tput sgr0) # \e[0m
PS1='\[$cyan\]My prompt\[$reset\]>'
See http://mywiki.wooledge.org/BashFAQ/053, and also http://wiki.bash-hackers.org/scripting/terminalcodes for more on tput
.
I wrote myself a little script using the fdisk command, based on what I know plus bits of code found online, which does something very similar, namely, interactively format a drive into one or more partitions, asking if this is the correct drive, waiting for a set time, or input from the user, warning it is about to erase it, etc. One thing it cannot do, in its current form, is resume running after it's stopped for any reason, from getting the input "No, don't format!" from the user, or simply an error. Once it stops, it has to be run again.
Note: $(echo $Output_Device) is a shell variable, and can be replaced with e.g. sdb or any similar name for a disk device.
The actual fdisk command(s) I cobbled together are:
Formats the disk into two partitions, 1 of size 64Mb, and 2 the rest of the disk:
(echo o; echo n; echo p; echo 1; echo ""; echo +64M; echo n; echo p; echo 2; echo ""; echo ""; echo w; echo q) | fdisk /dev/$(echo $Output_Device)
Then, actually formats the partitions, 1 as FAT, 2 as ext3:
mkfs.vfat -n BOOT /dev/$(echo $Output_Device)1
mkfs.ext3 -L root /dev/$(echo $Output_Device)2
I can post the whole script, but it is messy, and I like to keep commands in it even when they're commented out, for my own reference.
The more general case, how to make it resume, I may or may not be able to do, haven't tried. Likewise, this works with fdisk, but other commands may/will need a different syntax.
Best Answer
Bash does have that feature too, but it's not enabled by default. You can bind it to cursor up/down by sticking this into
~/.inputrc
:I prefer to bind it to Ctrl+up/down instead:
edit: To preserve ctrl+left and ctrl+right for moving back and forward in whole words, also include these lines in
~/.inputrc
file: