From d3e20724e92534e0c6a7736c2ba0d81563db39c3 Mon Sep 17 00:00:00 2001 From: Vincent De Smet Date: Wed, 30 Nov 2016 11:12:34 +0800 Subject: [PATCH] Add fancy bash prompt from orchestration workshop (#28) * Add bash prompt * remove curly braces * Change shell from ash to bash * Add inputrc for bash --- .bashrc | 1 + .inputrc | 73 +++++++++++++++++++++++++++++++++++++++++++++++++ vimrc => .vimrc | 0 Dockerfile.dind | 9 +++--- docker-prompt | 22 +++++++++++++++ 5 files changed, 101 insertions(+), 4 deletions(-) create mode 100644 .bashrc create mode 100644 .inputrc rename vimrc => .vimrc (100%) create mode 100755 docker-prompt diff --git a/.bashrc b/.bashrc new file mode 100644 index 0000000..9460e45 --- /dev/null +++ b/.bashrc @@ -0,0 +1 @@ +export PS1='\e[1m\e[31m[\h] \e[32m($(docker-prompt)) \e[34m\u@$(hostname -i)\e[35m \w\e[0m\n$ ' diff --git a/.inputrc b/.inputrc new file mode 100644 index 0000000..6a5b035 --- /dev/null +++ b/.inputrc @@ -0,0 +1,73 @@ +# /etc/inputrc - global inputrc for libreadline +# See readline(3readline) and `info rluserman' for more information. + +# Be 8 bit clean. +set input-meta on +set output-meta on + +# To allow the use of 8bit-characters like the german umlauts, uncomment +# the line below. However this makes the meta key not work as a meta key, +# which is annoying to those which don't need to type in 8-bit characters. + +# set convert-meta off + +# try to enable the application keypad when it is called. Some systems +# need this to enable the arrow keys. +# set enable-keypad on + +# see /usr/share/doc/bash/inputrc.arrows for other codes of arrow keys + +# do not bell on tab-completion +# set bell-style none +# set bell-style visible + +# some defaults / modifications for the emacs mode +$if mode=emacs + +# allow the use of the Home/End keys +"\e[1~": beginning-of-line +"\e[4~": end-of-line + +# allow the use of the Delete/Insert keys +"\e[3~": delete-char +"\e[2~": quoted-insert + +# mappings for "page up" and "page down" to step to the beginning/end +# of the history +# "\e[5~": beginning-of-history +# "\e[6~": end-of-history + +# alternate mappings for "page up" and "page down" to search the history +# "\e[5~": history-search-backward +# "\e[6~": history-search-forward + +# mappings for Ctrl-left-arrow and Ctrl-right-arrow for word moving +"\e[1;5C": forward-word +"\e[1;5D": backward-word +"\e[5C": forward-word +"\e[5D": backward-word +"\e\e[C": forward-word +"\e\e[D": backward-word + +$if term=rxvt +"\e[7~": beginning-of-line +"\e[8~": end-of-line +"\eOc": forward-word +"\eOd": backward-word +$endif + +# for non RH/Debian xterm, can't hurt for RH/Debian xterm +# "\eOH": beginning-of-line +# "\eOF": end-of-line + +# for freebsd console +# "\e[H": beginning-of-line +# "\e[F": end-of-line + +$endif + +# faster completion +set show-all-if-ambiguous on + +"\e[A": history-search-backward +"\e[B": history-search-forward diff --git a/vimrc b/.vimrc similarity index 100% rename from vimrc rename to .vimrc diff --git a/Dockerfile.dind b/Dockerfile.dind index 25d3614..10c6b9f 100644 --- a/Dockerfile.dind +++ b/Dockerfile.dind @@ -2,7 +2,7 @@ FROM docker:1.13.0-rc2-dind ENV DOCKER_STORAGE_DRIVER=overlay2 -RUN apk add --no-cache git tmux py-pip apache2-utils vim build-base gettext-dev curl +RUN apk add --no-cache git tmux py-pip apache2-utils vim build-base gettext-dev curl bash # Install Compose and Machine RUN pip install docker-compose==1.9.0 @@ -21,8 +21,9 @@ RUN mkdir -p /opt && cd /opt && \ # (note: we can't just symlink to /bin/true because it might be busybox) RUN rm /sbin/modprobe && echo '#!/bin/true' >/sbin/modprobe && chmod +x /sbin/modprobe -# Install a nice vimrc file -COPY vimrc /root/.vimrc +# Install a nice vimrc file and prompt (by soulshake) +COPY ["docker-prompt","/usr/local/bin/"] +COPY [".vimrc",".bashrc", ".inputrc", "./root/"] # Move to our home WORKDIR /root @@ -32,5 +33,5 @@ CMD cat /etc/hosts >/etc/hosts.bak && \ sed 's/^::1.*//' /etc/hosts.bak > /etc/hosts && \ dockerd -g /graph --host=unix:///var/run/docker.sock --host=tcp://0.0.0.0:2375 \ --storage-driver=$DOCKER_STORAGE_DRIVER &>/docker.log & \ - while true ; do /bin/sh ; done + while true ; do /bin/bash ; done # ... and then put a shell in the foreground, restarting it if it exits diff --git a/docker-prompt b/docker-prompt new file mode 100755 index 0000000..3df79d2 --- /dev/null +++ b/docker-prompt @@ -0,0 +1,22 @@ + +#!/bin/sh +case "$DOCKER_HOST" in +*:3376) + echo swarm + ;; +*:2376) + echo $DOCKER_MACHINE_NAME + ;; +*:2375) + echo $DOCKER_MACHINE_NAME + ;; +*:55555) + echo $DOCKER_MACHINE_NAME + ;; +"") + echo local + ;; +*) + echo unknown + ;; +esac