From cf75ab6060111cab90b4b3f58505e81136d8cecf Mon Sep 17 00:00:00 2001 From: Inti Gabriel Date: Sat, 16 May 2015 13:53:10 +0200 Subject: [PATCH] Fixes wolfspyre/puppet-bashrc#5 - as mentioned by Matti_Kurkela check call of tput in non tty environment - see http://h30499.www3.hp.com/t5/System-Administration/SSH-session-quot-tput-No-value-for-TERM-and-no-T-specified/td-p/5255040#.VVIX25PanYh --- spec/classes/bashrc_spec.rb | 2 +- templates/prompt.sh.erb | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/spec/classes/bashrc_spec.rb b/spec/classes/bashrc_spec.rb index 7a3b069..6dcf2d5 100644 --- a/spec/classes/bashrc_spec.rb +++ b/spec/classes/bashrc_spec.rb @@ -85,7 +85,7 @@ :owner=>"0", :group=>"0", :mode=>"0555", - :content=>"#!/bin/bash\n#\n#this file is responsible for setting the bash shell prompt for a user. it builds the prompt from values\n# fed to the bashrc module\n#Enable Colors\nreset=$(tput sgr0)\nred=$(tput setaf 1)\ngreen=$(tput setaf 2)\nyellow=$(tput setaf 3)\nblue=$(tput setaf 4)\npurple=$(tput setaf 5)\ncyan=$(tput setaf 6)\nwhite=$(tput setaf 7)\ncolone=$blue\ncoltwo=$white\ngitcol=$yellow\nif [ -f ~/.bashrc ]; then\n #we have a user-specific bashrc. Hook into it so we're confident we get run \"last\"\n if [ `grep -c /etc/profile.d/prompt.sh ~/.bashrc` -lt 1 ]; then\n #we don't seem to have already introduced ourselves to the user's bashrc file. Lets go introduce ourselves\n echo '#set the prompt to include nice pretty colors. Courtesy of bashrc::prompt, most specifically /etc/profile.d/prompt.sh' >> ~/.bashrc\n echo '. /etc/profile.d/prompt.sh' >> ~/.bashrc\n fi\nfi\n\nif [ $UID -eq 0 ]; then\n export PS1=\"\\[$red\\][\\[$colone\\]\\u\\[$white\\]@\\[$coltwo\\]\\h \\W\\[$gitcol\\]\\$(__git_ps1)\\[$reset\\]\\[$red\\]]\\[$reset\\]# \"\nelse\n export PS1=\"[\\[$colone\\]\\u\\[$white\\]@\\[$coltwo\\]\\h \\W\\[$gitcol\\]\\$(__git_ps1)\\[$reset\\]]\\$ \"\nfi\n" + :content=>"#!/bin/bash\n#\n#this file is responsible for setting the bash shell prompt for a user. it builds the prompt from values\n# fed to the bashrc module\n#Enable Colors\nreset=$(tty -s && tput sgr0)\nred=$(tty -s && tput setaf 1)\ngreen=$(tty -s && tput setaf 2)\nyellow=$(tty -s && tput setaf 3)\nblue=$(tty -s && tput setaf 4)\npurple=$(tty -s && tput setaf 5)\ncyan=$(tty -s && tput setaf 6)\nwhite=$(tty -s && tput setaf 7)\ncolone=$blue\ncoltwo=$white\ngitcol=$yellow\nif [ -f ~/.bashrc ]; then\n #we have a user-specific bashrc. Hook into it so we're confident we get run \"last\"\n if [ `grep -c /etc/profile.d/prompt.sh ~/.bashrc` -lt 1 ]; then\n #we don't seem to have already introduced ourselves to the user's bashrc file. Lets go introduce ourselves\n echo '#set the prompt to include nice pretty colors. Courtesy of bashrc::prompt, most specifically /etc/profile.d/prompt.sh' >> ~/.bashrc\n echo '. /etc/profile.d/prompt.sh' >> ~/.bashrc\n fi\nfi\n\nif [ $UID -eq 0 ]; then\n export PS1=\"\\[$red\\][\\[$colone\\]\\u\\[$white\\]@\\[$coltwo\\]\\h \\W\\[$gitcol\\]\\$(__git_ps1)\\[$reset\\]\\[$red\\]]\\[$reset\\]# \"\nelse\n export PS1=\"[\\[$colone\\]\\u\\[$white\\]@\\[$coltwo\\]\\h \\W\\[$gitcol\\]\\$(__git_ps1)\\[$reset\\]]\\$ \"\nfi\n" }) end diff --git a/templates/prompt.sh.erb b/templates/prompt.sh.erb index 94bb79a..16800ae 100644 --- a/templates/prompt.sh.erb +++ b/templates/prompt.sh.erb @@ -15,14 +15,14 @@ # fed to the bashrc module <% if enablecolor == true -%> #Enable Colors -reset=$(tput sgr0) -red=$(tput setaf 1) -green=$(tput setaf 2) -yellow=$(tput setaf 3) -blue=$(tput setaf 4) -purple=$(tput setaf 5) -cyan=$(tput setaf 6) -white=$(tput setaf 7) +reset=$(tty -s && tput sgr0) +red=$(tty -s && tput setaf 1) +green=$(tty -s && tput setaf 2) +yellow=$(tty -s && tput setaf 3) +blue=$(tty -s && tput setaf 4) +purple=$(tty -s && tput setaf 5) +cyan=$(tty -s && tput setaf 6) +white=$(tty -s && tput setaf 7) colone=$<%= colone %> coltwo=$<%= coltwo %> <% if enablegit == true -%>