aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2013-03-28 13:20:12 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2013-03-28 13:20:12 +0100
commit6c852bfcadd78f53ec7a5f35882636a2a4a66eb0 (patch)
treed70511de9bde3fcefa3e8a60dee33a9c0882459e
parent2c24806bf48cddcdaa32d654986e5c275a3d34f6 (diff)
downloadbusybox-w32-6c852bfcadd78f53ec7a5f35882636a2a4a66eb0.tar.gz
busybox-w32-6c852bfcadd78f53ec7a5f35882636a2a4a66eb0.tar.bz2
busybox-w32-6c852bfcadd78f53ec7a5f35882636a2a4a66eb0.zip
lineedit: add handling of \H in prompt
Based on the patch by Arnaud RĂ©billout <rebillout@syscom.ch> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--libbb/lineedit.c50
1 files changed, 45 insertions, 5 deletions
diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index 52b49e8a9..591bb6d5e 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -1789,7 +1789,44 @@ static void parse_and_put_prompt(const char *prmt_ptr)
1789 if (c == '\\') { 1789 if (c == '\\') {
1790 const char *cp = prmt_ptr; 1790 const char *cp = prmt_ptr;
1791 int l; 1791 int l;
1792 1792/*
1793 * Supported via bb_process_escape_sequence:
1794 * \a ASCII bell character (07)
1795 * \e ASCII escape character (033)
1796 * \n newline
1797 * \r carriage return
1798 * \\ backslash
1799 * \nnn char with octal code nnn
1800 * Supported:
1801 * \$ if the effective UID is 0, a #, otherwise a $
1802 * \! history number of this command
1803 * (buggy?)
1804 * \w current working directory, with $HOME abbreviated with a tilde
1805 * Note: we do not support $PROMPT_DIRTRIM=n feature
1806 * \h hostname up to the first '.'
1807 * \H hostname
1808 * \u username
1809 * \[ begin a sequence of non-printing characters
1810 * \] end a sequence of non-printing characters
1811 * Not supported:
1812 * \# command number of this command
1813 * \j number of jobs currently managed by the shell
1814 * \l basename of the shell's terminal device name
1815 * \s name of the shell, the basename of $0 (the portion following the final slash)
1816 * \V release of bash, version + patch level (e.g., 2.00.0)
1817 * \W basename of the current working directory, with $HOME abbreviated with a tilde
1818 * \d date in "Weekday Month Date" format (e.g., "Tue May 26")
1819 * \D{format}
1820 * format is passed to strftime(3).
1821 * An empty format results in a locale-specific time representation.
1822 * The braces are required.
1823 * \T current time in 12-hour HH:MM:SS format
1824 * \@ current time in 12-hour am/pm format
1825 * \A current time in 24-hour HH:MM format
1826 * Mishandled by bb_process_escape_sequence:
1827 * \t current time in 24-hour HH:MM:SS format
1828 * \v version of bash (e.g., 2.00)
1829 */
1793 c = bb_process_escape_sequence(&prmt_ptr); 1830 c = bb_process_escape_sequence(&prmt_ptr);
1794 if (prmt_ptr == cp) { 1831 if (prmt_ptr == cp) {
1795 if (*cp == '\0') 1832 if (*cp == '\0')
@@ -1802,9 +1839,11 @@ static void parse_and_put_prompt(const char *prmt_ptr)
1802 pbuf = user_buf ? user_buf : (char*)""; 1839 pbuf = user_buf ? user_buf : (char*)"";
1803 break; 1840 break;
1804# endif 1841# endif
1842 case 'H':
1805 case 'h': 1843 case 'h':
1806 pbuf = free_me = safe_gethostname(); 1844 pbuf = free_me = safe_gethostname();
1807 *strchrnul(pbuf, '.') = '\0'; 1845 if (c == 'h')
1846 strchrnul(pbuf, '.')[0] = '\0';
1808 break; 1847 break;
1809 case '$': 1848 case '$':
1810 c = (geteuid() == 0 ? '#' : '$'); 1849 c = (geteuid() == 0 ? '#' : '$');
@@ -1832,9 +1871,10 @@ static void parse_and_put_prompt(const char *prmt_ptr)
1832 case '!': 1871 case '!':
1833 pbuf = free_me = xasprintf("%d", num_ok_lines); 1872 pbuf = free_me = xasprintf("%d", num_ok_lines);
1834 break; 1873 break;
1835 case 'e': case 'E': /* \e \E = \033 */ 1874// bb_process_escape_sequence does this now:
1836 c = '\033'; 1875// case 'e': case 'E': /* \e \E = \033 */
1837 break; 1876// c = '\033';
1877// break;
1838 case 'x': case 'X': { 1878 case 'x': case 'X': {
1839 char buf2[4]; 1879 char buf2[4];
1840 for (l = 0; l < 3;) { 1880 for (l = 0; l < 3;) {