Bash Prompt HOWTO

Total Page:16

File Type:pdf, Size:1020Kb

Bash Prompt HOWTO Bash Prompt HOWTO $Revision$, $Date$ Giles Orr Bash Prompt HOWTO: $Revision$, $Date$ by Giles Orr Copyright © 1998, 1999, 2000, 2001, 2003 Giles Orr Creating and controlling terminal and xterm prompts is discussed, including incorporating standard escape sequences to give username, current working directory, time, etc. Further suggestions are made on how to modify xterm title bars, use external functions to provide prompt information, and how to use ANSI colours. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License". Table of Contents 1. Introduction and Administrivia...........................................................................................................1 1.1. Introduction.................................................................................................................................1 1.2. Revision History..........................................................................................................................1 1.3. Requirements..............................................................................................................................1 1.4. How To Use This Document.......................................................................................................2 1.5. Document Versions, Comments and Suggestions.......................................................................2 1.6. Problems......................................................................................................................................2 1.7. Credits/Bibliography...................................................................................................................3 1.8. Disclaimer...................................................................................................................................4 2. Bash and Bash Prompts........................................................................................................................5 2.1. What is Bash?..............................................................................................................................5 2.2. What Can Tweaking Your Bash Prompt Do For You?................................................................5 2.3. Why Bother?...............................................................................................................................5 2.4. The First Step..............................................................................................................................5 2.5. Bash Prompt Escape Sequences..................................................................................................6 2.6. Setting the PS? Strings Permanently...........................................................................................8 3. Bash Programming and Shell Scripts..................................................................................................9 3.1. Variables......................................................................................................................................9 3.2. Quotes and Special Characters....................................................................................................9 3.3. Command Substitution..............................................................................................................10 3.4. Non-Printing Characters in Prompts.........................................................................................10 3.5. Sourcing a File..........................................................................................................................11 3.6. Functions, Aliases, and the Environment..................................................................................12 4. External Commands............................................................................................................................14 4.1. PROMPT_COMMAND............................................................................................................14 4.2. External Commands in the Prompt...........................................................................................14 4.3. What to Put in Your Prompt......................................................................................................15 5. Saving Complex Prompts....................................................................................................................17 6. ANSI Escape Sequences: Colours and Cursor Movement..............................................................19 6.1. Colours......................................................................................................................................19 6.2. Cursor Movement......................................................................................................................21 6.3. Xterm Title Bar Manipulations.................................................................................................23 6.4. Xterm Title Bars and Screen.....................................................................................................24 6.5. Colours and Cursor Movement With tput ................................................................................25 7. Special Characters: Octal Escape Sequences....................................................................................29 8. The Bash Prompt Package..................................................................................................................31 8.1. Availability................................................................................................................................31 8.2. Xterm Fonts...............................................................................................................................31 8.3. Changing the Xterm Font..........................................................................................................31 8.4. Line Draw Characters without VGA Fonts...............................................................................32 iii 9. Loading a Different Prompt................................................................................................................33 9.1. Loading a Different Prompt, Later............................................................................................33 9.2. Loading a Different Prompt, Immediately................................................................................33 9.3. Loading Different Prompts in Different X Terms.....................................................................33 10. Loading Prompt Colours Dynamically............................................................................................35 10.1. A "Proof of Concept" Example...............................................................................................35 11. Prompt Code Snippets.......................................................................................................................37 11.1. Built-in Escape Sequences......................................................................................................37 11.2. Date and Time.........................................................................................................................37 11.3. Counting Files in the Current Directory.................................................................................37 11.4. Total Bytes in the Current Directory.......................................................................................38 11.5. Checking the Current TTY.....................................................................................................39 11.6. Stopped Jobs Count.................................................................................................................39 11.7. Load........................................................................................................................................40 11.8. Uptime.....................................................................................................................................41 11.9. Number of Processes...............................................................................................................42 11.10. Controlling the Size and Appearance of $PWD...................................................................42 11.11. Laptop Power........................................................................................................................43 11.12. Having the Prompt Ignored on Cut and Paste.......................................................................43 11.13. New Mail...............................................................................................................................44 11.14. Prompt Beeps After Long-Running Commands...................................................................44 12. Example Prompts...............................................................................................................................47 12.1. Examples on the Web..............................................................................................................47 12.2. A "Lightweight" Prompt.........................................................................................................47
Recommended publications
  • Linux on the Road
    Linux on the Road Linux with Laptops, Notebooks, PDAs, Mobile Phones and Other Portable Devices Werner Heuser <wehe[AT]tuxmobil.org> Linux Mobile Edition Edition Version 3.22 TuxMobil Berlin Copyright © 2000-2011 Werner Heuser 2011-12-12 Revision History Revision 3.22 2011-12-12 Revised by: wh The address of the opensuse-mobile mailing list has been added, a section power management for graphics cards has been added, a short description of Intel's LinuxPowerTop project has been added, all references to Suspend2 have been changed to TuxOnIce, links to OpenSync and Funambol syncronization packages have been added, some notes about SSDs have been added, many URLs have been checked and some minor improvements have been made. Revision 3.21 2005-11-14 Revised by: wh Some more typos have been fixed. Revision 3.20 2005-11-14 Revised by: wh Some typos have been fixed. Revision 3.19 2005-11-14 Revised by: wh A link to keytouch has been added, minor changes have been made. Revision 3.18 2005-10-10 Revised by: wh Some URLs have been updated, spelling has been corrected, minor changes have been made. Revision 3.17.1 2005-09-28 Revised by: sh A technical and a language review have been performed by Sebastian Henschel. Numerous bugs have been fixed and many URLs have been updated. Revision 3.17 2005-08-28 Revised by: wh Some more tools added to external monitor/projector section, link to Zaurus Development with Damn Small Linux added to cross-compile section, some additions about acoustic management for hard disks added, references to X.org added to X11 sections, link to laptop-mode-tools added, some URLs updated, spelling cleaned, minor changes.
    [Show full text]
  • Cygwin User's Guide
    Cygwin User’s Guide Cygwin User’s Guide ii Copyright © Cygwin authors Permission is granted to make and distribute verbatim copies of this documentation provided the copyright notice and this per- mission notice are preserved on all copies. Permission is granted to copy and distribute modified versions of this documentation under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one. Permission is granted to copy and distribute translations of this documentation into another language, under the above conditions for modified versions, except that this permission notice may be stated in a translation approved by the Free Software Foundation. Cygwin User’s Guide iii Contents 1 Cygwin Overview 1 1.1 What is it? . .1 1.2 Quick Start Guide for those more experienced with Windows . .1 1.3 Quick Start Guide for those more experienced with UNIX . .1 1.4 Are the Cygwin tools free software? . .2 1.5 A brief history of the Cygwin project . .2 1.6 Highlights of Cygwin Functionality . .3 1.6.1 Introduction . .3 1.6.2 Permissions and Security . .3 1.6.3 File Access . .3 1.6.4 Text Mode vs. Binary Mode . .4 1.6.5 ANSI C Library . .4 1.6.6 Process Creation . .5 1.6.6.1 Problems with process creation . .5 1.6.7 Signals . .6 1.6.8 Sockets . .6 1.6.9 Select . .7 1.7 What’s new and what changed in Cygwin . .7 1.7.1 What’s new and what changed in 3.2 .
    [Show full text]
  • Fira Code: Monospaced Font with Programming Ligatures
    Personal Open source Business Explore Pricing Blog Support This repository Sign in Sign up tonsky / FiraCode Watch 282 Star 9,014 Fork 255 Code Issues 74 Pull requests 1 Projects 0 Wiki Pulse Graphs Monospaced font with programming ligatures 145 commits 1 branch 15 releases 32 contributors OFL-1.1 master New pull request Find file Clone or download lf- committed with tonsky Add mintty to the ligatures-unsupported list (#284) Latest commit d7dbc2d 16 days ago distr Version 1.203 (added `__`, closes #120) a month ago showcases Version 1.203 (added `__`, closes #120) a month ago .gitignore - Removed `!!!` `???` `;;;` `&&&` `|||` `=~` (closes #167) `~~~` `%%%` 3 months ago FiraCode.glyphs Version 1.203 (added `__`, closes #120) a month ago LICENSE version 0.6 a year ago README.md Add mintty to the ligatures-unsupported list (#284) 16 days ago gen_calt.clj Removed `/**` `**/` and disabled ligatures for `/*/` `*/*` sequences … 2 months ago release.sh removed Retina weight from webfonts 3 months ago README.md Fira Code: monospaced font with programming ligatures Problem Programmers use a lot of symbols, often encoded with several characters. For the human brain, sequences like -> , <= or := are single logical tokens, even if they take two or three characters on the screen. Your eye spends a non-zero amount of energy to scan, parse and join multiple characters into a single logical one. Ideally, all programming languages should be designed with full-fledged Unicode symbols for operators, but that’s not the case yet. Solution Download v1.203 · How to install · News & updates Fira Code is an extension of the Fira Mono font containing a set of ligatures for common programming multi-character combinations.
    [Show full text]
  • Mupif.Org Platform User Manual Authors: B
    MuPIF.org Platform User Manual Authors: B. Patzák​1 ​and V. Šmilauer1 Version 1.1.2 - 8/2017 1 Czech Technical University, Faculty of Civil Engineering, Department of Mechanics, Thákurova 7, 16629, Prague, Czech Republic. 1/54 1. Table of Content 1. Table of Content 2. Introduction 3. Platform installation 3.1. Prerequisites 3.1.1. Windows platforms 3.1.2. Linux / Unix (*nix) platforms 3.1.3. General requirements 3.1.4. Other recommended packages/softwares 3.2. Installing the MuPIF platform 3.3. Verifying platform installation 3.3.1. Running unit tests 3.3.2. Running examples 4. Platform operations 5. Platform APIs 5.1. Application class 5.2. Property class 5.3. Field class 5.4. Function class 5.5. TimeStep class 5.6. Mesh class 5.7. Cell class 5.8. Vertex class 5.9. BoundingBox 5.10. APIError 6. Developing Application Program Interface (API) 7. Developing user workflows 7.2 Workflow templates 7.3 Workflow example 7.4 Workflow as a class 8. Distributed Model 8.1. Distributed aspects of the API 8.2. Requirements for distributed computing 8.3. Internal platform solution - JobManager resource allocation 2/54 8.3.1. Setting up a Job Manager 8.3.2. Configuration 8.4. Securing the communication using SSH tunnels 8.4.1. Setting up ssh server 8.4.2. Example of distributed scenario with ssh tunneling 8.4.3. Advanced SSH setting 8.5. Using Virtual Private Network (VPN) 8.5.1. Generalities 8.5.2. Setup 8.5.3. Example of simulation scenario using VPN 9.
    [Show full text]
  • CLI Introduction
    2021/07/26 13:46 (UTC) 1/3 CLI Introduction Por traducir - Victor CLI Introduction A command line interface (CLI) is a way of interacting with an operating system or programs using text commands. As opposed to graphical user interfaces (GUI), CLI, due to its nature, is heavily keyboard oriented. Despite a steeper learning curve, this way of interaction has a wide range of benefits and is therefore preferred by many users. Since most Slackware configuration and administration is performed using the command line interface, it is highly recommended to understand and feel comfortable using them. An additional advantage is that 99% of the commands are universal for most Linux distributions. Things you learn here will most probably be applicable elsewhere. CLI is Good - Do Not Fear It The following are some of the advantages to using CLI: 1. CLI commands are more precise and powerful than GUI interaction. 2. GUI tools are often just frontends for command line tools. This brings another layer of complexity and is more difficult to troubleshoot. 3. Most commands are distro agnostic: they work on other Linux systems as well. 4. CLI commands are building blocks that can be glued together to create complex commands or custom scripts that are tailored to your needs. 5. CLI commands can be used to automate repetitive tasks 6. CLI commands do not change often. 7. Commands make a universal language that is easy to communicate and follow by other internet users. 8. CLI scripts can include comments that can act as notes and internal documentation explaining the functionality and simplifying future modifications.
    [Show full text]
  • Cygwin User's Guide
    Cygwin User’s Guide i Cygwin User’s Guide Cygwin User’s Guide ii Copyright © 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Red Hat, Inc. Permission is granted to make and distribute verbatim copies of this documentation provided the copyright notice and this per- mission notice are preserved on all copies. Permission is granted to copy and distribute modified versions of this documentation under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one. Permission is granted to copy and distribute translations of this documentation into another language, under the above conditions for modified versions, except that this permission notice may be stated in a translation approved by the Free Software Foundation. Cygwin User’s Guide iii Contents 1 Cygwin Overview 1 1.1 What is it? . .1 1.2 Quick Start Guide for those more experienced with Windows . .1 1.3 Quick Start Guide for those more experienced with UNIX . .1 1.4 Are the Cygwin tools free software? . .2 1.5 A brief history of the Cygwin project . .2 1.6 Highlights of Cygwin Functionality . .3 1.6.1 Introduction . .3 1.6.2 Permissions and Security . .3 1.6.3 File Access . .3 1.6.4 Text Mode vs. Binary Mode . .4 1.6.5 ANSI C Library . .5 1.6.6 Process Creation . .5 1.6.6.1 Problems with process creation . .5 1.6.7 Signals . .6 1.6.8 Sockets . .6 1.6.9 Select .
    [Show full text]
  • Xterm Control Sequences
    Xterm Control Sequences EdwardMoy University of California, Berkeley Revised by Stephen Gildea XConsortium (1994) Thomas Dickey XFree86 Project (1996-2003) Definitions c The literal character c. C Asingle (required) character. Ps Asingle (usually optional) numeric parameter,composed of one of more digits. Pm Amultiple numeric parameter composed of anynumber of single numeric parameters, separated by ;char- acter(s). Individual values for the parameters are listed with Ps . Pt Atextparameter composed of printable characters. C1 (8-Bit) Control Characters The xterm program recognizes both 8-bit and 7-bit control characters. It generates 7-bit controls (by default) or 8-bit if S8C1T is enabled. The following pairs of 7-bit and 8-bit control characters are equivalent: ESC D Index(IND is 0x84) ESC E Next Line ( NEL is 0x85) ESC H TabSet ( HTS is 0x88) ESC M Reverse Index( RI is 0x8d) ESC N Single Shift Select of G2 Character Set ( SS2 is 0x8e): affects next character only ESC O Single Shift Select of G3 Character Set ( SS3 is 0x8f): affects next character only ESC P Device Control String ( DCS is 0x90) ESC V Start of Guarded Area ( SPA is 0x96) Xterm Control Sequences C1 (8-Bit) Control Characters ESC W End of Guarded Area ( EPA is 0x97) ESC X Start of String ( SOS is 0x98) ESC Z Return Terminal ID (DECID is 0x9a). Obsolete form of CSI c(DA). ESC [ Control Sequence Introducer ( CSI is 0x9b) ESC \ String Terminator ( ST is 0x9c) ESC ] Operating System Command ( OSC is 0x9d) ESC ^ Privacy Message ( PM is 0x9e) ESC _ Application Program Command ( APC is 0x9f) These control characters are used in the vtXXX emulation.
    [Show full text]
  • On Z/OS and OS/390 UNIX
    C/C++ Applications on z/OS and OS/390 UNIX Port UNIX C/C++ applications to z/OS Write portable C/C++ applications Real-world port described Michael MacIsaac Ralph Best Johan Koppernaes Ka Yin Lam Raymond Mak Daniel Prevost George Reid ibm.com/redbooks International Technical Support Organization C/C++ Applications on z/OS and OS/390 UNIX December 2001 SG24-5992-01 Take Note! Before using this information and the product it supports, be sure to read the general information in “Special notices” on page 205. Second Edition (December 2001) This edition applies to version 1, release 2 of z/OS and earlier releases of OS/390, program number 5647-A01. Comments may be addressed to: IBM Corporation, International Technical Support Organization Dept. HYJ Mail Station P099 2455 South Road Poughkeepsie, NY 12601-5400 When you send information to IBM, you grant IBM a non-exclusive right to use or distribute the information in any way it believes appropriate without incurring any obligation to you. © Copyright International Business Machines Corporation 2000, 2001. All rights reserved. Note to U.S Government Users - Documentation related to restricted rights - Use, duplication or disclosure is subject to restrictions set forth in GSA ADP Schedule Contract with IBM Corp. Contents Contents . iii Preface . ix The team that wrote this redbook. ix Special notice. .x IBM trademarks . xi Comments welcome. xi Summary of changes. xiii December 2001, Second Edition . xiii Chapter 1. z/OS and OS/390 tools . 1 1.1 User access under z/OS . 2 1.1.1 JCL and batch. 2 1.1.2 JOB statement .
    [Show full text]
  • Polishing the Terminal Window with Bashish COLORCOLOR MYMY SHELLSHELL
    LINUXUSER Bashish Polishing the terminal window with Bashish COLORCOLOR MYMY SHELLSHELL Bashish adds a dash of style to the command line. BY FRANK WIEDUWILT Orchidpoet, Fotolia Orchidpoet, f you are a regular command line To install a functional version of Bash- You can now launch a new shell by user, you may appreciate the spartan ish, you will need a recent version of the entering the exec bash command. The Iappearance of the terminal window. Bourne Again Shell (Bash), version 2.04 new shell will reflect the default Bashish But for occasional shell users, or readers or newer. You’ll also need a recent ver- settings, which call for a light blue font who would prefer a more playful ap- sion of your terminal program. on a black background. To remove Bash- proach, Bashish [1] opens a treasure We were unable to use Bashish with ish, just launch the program with the trove of options. Bashish gives your ter- the Rxvt version included with Mandriva --uninstall flag. minal window a colorful ASCII graphic 2006. The terminal program crashed background. with most of the themes we tried. In Shell Colors Bashish lets you liven up the appear- contrast, the version of Bashish provided Bashish groups shell enhancements in ance of terminal programs such as with Ubuntu 6.06 worked without any what are called themes. A theme in- Gnome Terminal, Xterm, Rxvt, Rxvt trouble, as did the Rxvt version with cludes the data for the background Unicode, Aterm, Mlterm, and the Linux Suse 10.1. After we switched to the Rx- graphic and the prompt.
    [Show full text]
  • The Linux Command Line
    The Linux Command Line Second Internet Edition William E. Shotts, Jr. A LinuxCommand.org Book Copyright ©2008-2013, William E. Shotts, Jr. This work is licensed under the Creative Commons Attribution-Noncommercial-No De- rivative Works 3.0 United States License. To view a copy of this license, visit the link above or send a letter to Creative Commons, 171 Second Street, Suite 300, San Fran- cisco, California, 94105, USA. Linux® is the registered trademark of Linus Torvalds. All other trademarks belong to their respective owners. This book is part of the LinuxCommand.org project, a site for Linux education and advo- cacy devoted to helping users of legacy operating systems migrate into the future. You may contact the LinuxCommand.org project at http://linuxcommand.org. This book is also available in printed form, published by No Starch Press and may be purchased wherever fine books are sold. No Starch Press also offers this book in elec- tronic formats for most popular e-readers: http://nostarch.com/tlcl.htm Release History Version Date Description 13.07 July 6, 2013 Second Internet Edition. 09.12 December 14, 2009 First Internet Edition. 09.11 November 19, 2009 Fourth draft with almost all reviewer feedback incorporated and edited through chapter 37. 09.10 October 3, 2009 Third draft with revised table formatting, partial application of reviewers feedback and edited through chapter 18. 09.08 August 12, 2009 Second draft incorporating the first editing pass. 09.07 July 18, 2009 Completed first draft. Table of Contents Introduction....................................................................................................xvi
    [Show full text]
  • Pipenightdreams Osgcal-Doc Mumudvb Mpg123-Alsa Tbb
    pipenightdreams osgcal-doc mumudvb mpg123-alsa tbb-examples libgammu4-dbg gcc-4.1-doc snort-rules-default davical cutmp3 libevolution5.0-cil aspell-am python-gobject-doc openoffice.org-l10n-mn libc6-xen xserver-xorg trophy-data t38modem pioneers-console libnb-platform10-java libgtkglext1-ruby libboost-wave1.39-dev drgenius bfbtester libchromexvmcpro1 isdnutils-xtools ubuntuone-client openoffice.org2-math openoffice.org-l10n-lt lsb-cxx-ia32 kdeartwork-emoticons-kde4 wmpuzzle trafshow python-plplot lx-gdb link-monitor-applet libscm-dev liblog-agent-logger-perl libccrtp-doc libclass-throwable-perl kde-i18n-csb jack-jconv hamradio-menus coinor-libvol-doc msx-emulator bitbake nabi language-pack-gnome-zh libpaperg popularity-contest xracer-tools xfont-nexus opendrim-lmp-baseserver libvorbisfile-ruby liblinebreak-doc libgfcui-2.0-0c2a-dbg libblacs-mpi-dev dict-freedict-spa-eng blender-ogrexml aspell-da x11-apps openoffice.org-l10n-lv openoffice.org-l10n-nl pnmtopng libodbcinstq1 libhsqldb-java-doc libmono-addins-gui0.2-cil sg3-utils linux-backports-modules-alsa-2.6.31-19-generic yorick-yeti-gsl python-pymssql plasma-widget-cpuload mcpp gpsim-lcd cl-csv libhtml-clean-perl asterisk-dbg apt-dater-dbg libgnome-mag1-dev language-pack-gnome-yo python-crypto svn-autoreleasedeb sugar-terminal-activity mii-diag maria-doc libplexus-component-api-java-doc libhugs-hgl-bundled libchipcard-libgwenhywfar47-plugins libghc6-random-dev freefem3d ezmlm cakephp-scripts aspell-ar ara-byte not+sparc openoffice.org-l10n-nn linux-backports-modules-karmic-generic-pae
    [Show full text]
  • Linux Terminal for Mac
    Linux Terminal For Mac Ecuadoran Willie still hiccough: quadratic and well-kept Theodoric sculpts quite fawningly but dimple her sunns logically. Marc stay her brontosaurs sanguinarily, doughtier and dozing. Minim and unreligious Norm slid her micropalaeontology hysterectomized or thromboses vaingloriously. In linux command line tools are potholed and the compute nodes mount a bit of its efforts in way to terminal for linux mac vs code for. When troubleshooting problems that mac for linux shells and terminate driver backend, then launch step is usable or just stick with other folder in conjunction with. Mac OS X Rackspace Support. Execute properly for linux terminal for mac. Mac os x also a package manager like who are typing in there are used make mistakes. Add Git Branch personnel to obtain Prompt Mac Martin. How to mac to mac terminal for linux on which are. The terminal for a powerful commands have to learn to scroll though the utilities. Get you around, linux kernel for access management solutions for mac terminal for linux machines is a part: is independently of the app first five years of? Then hyper will be able to mac with references or space for mac terminal? The command will do so we will say various files up to get more advanced users requiring stability and selecting the rest of a program. Linux terminal for mac from a list in the arguments, i talking to ensure that. So that have much leaves OS X but I don't know just how terminal although it is. Terminal for mac or loss in! Now would have other documents into terminal for mac here is robust enough to free transfers that terminal program that homebrew on it for the commands in! How to Customize Your Mac's Terminal but Better Productivity.
    [Show full text]