Skip to content

Commit

Permalink
Use \033 instead of \e for color codes, which seems to be more widely…
Browse files Browse the repository at this point in the history
… supported.
  • Loading branch information
ndbroadbent committed Oct 23, 2012
1 parent 4d62b25 commit d6730b4
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 42 deletions.
2 changes: 1 addition & 1 deletion lib/git/branch_shortcuts.sh
Expand Up @@ -25,7 +25,7 @@ function _scmb_git_branch_shortcuts {
line_count = output.lines.to_a.size
output.lines.each_with_index do |line, i|
spaces = (line_count > 9 && i < 9 ? " " : " ")
puts line.sub(/^([ *]{2})/, "\\\1\e[2;37m[\e[0m#{i+1}\e[2;37m]\e[0m" << spaces)
puts line.sub(/^([ *]{2})/, "\\\1\033[2;37m[\033[0m#{i+1}\033[2;37m]\033[0m" << spaces)
end
EOF
)"
Expand Down
28 changes: 14 additions & 14 deletions lib/git/fallback/status_shortcuts_shell.sh
Expand Up @@ -35,17 +35,17 @@ git_status_shortcuts() {
fi

# Colors
local c_rst="\e[0m"
local c_branch="\e[1m"
local c_header="\e[0m"
local c_dark="\e[2;37m"
local c_del="\e[0;31m"
local c_mod="\e[0;32m"
local c_new="\e[0;33m"
local c_ren="\e[0;34m"
local c_cpy="\e[0;33m"
local c_ign="\e[0;36m"
# Following colors must be prepended with modifiers e.g. '\e[1;', '\e[0;'
local c_rst="\033[0m"
local c_branch="\033[1m"
local c_header="\033[0m"
local c_dark="\033[2;37m"
local c_del="\033[0;31m"
local c_mod="\033[0;32m"
local c_new="\033[0;33m"
local c_ren="\033[0;34m"
local c_cpy="\033[0;33m"
local c_ign="\033[0;36m"
# Following colors must be prepended with modifiers e.g. '\033[1;', '\033[0;'
local c_grp_1="33m"; local c_grp_2="31m"; local c_grp_3="32m"; local c_grp_4="36m"

local f=1; local e=1 # Counters for number of files, and ENV variables
Expand Down Expand Up @@ -100,8 +100,8 @@ git_status_shortcuts() {
for heading in 'Changes to be committed' 'Unmerged paths' 'Changes not staged for commit' 'Untracked files'; do
# If no group specified as param, or specified group is current group
if [ -z "$1" ] || [[ "$1" == "$grp_num" ]]; then
local c_arrow="\e[1;$(eval echo \$c_grp_$grp_num)"
local c_hash="\e[0;$(eval echo \$c_grp_$grp_num)"
local c_arrow="\033[1;$(eval echo \$c_grp_$grp_num)"
local c_hash="\033[0;$(eval echo \$c_grp_$grp_num)"
if [ -n "${stat_grp[$grp_num]}" ]; then
echo -e "$c_arrow$c_header $heading\n$c_hash#$c_rst"
_gs_output_file_group $grp_num
Expand All @@ -121,7 +121,7 @@ git_status_shortcuts() {
_gs_output_file_group() {
for i in ${stat_grp[$1]}; do
# Print colored hashes & files based on modification groups
local c_group="\e[0;$(eval echo -e \$c_grp_$1)"
local c_group="\033[0;$(eval echo -e \$c_grp_$1)"

# Deduce relative path based on current working directory
if [ -z "$project_root" ]; then
Expand Down
2 changes: 1 addition & 1 deletion lib/git/helpers.sh
Expand Up @@ -9,7 +9,7 @@ function find_in_cwd_or_parent() {

function fail_if_not_git_repo() {
if ! find_in_cwd_or_parent ".git" > /dev/null; then
echo -e "\e[31mNot a git repository (or any of the parent directories)\e[0m"
echo -e "\033[31mNot a git repository (or any of the parent directories)\033[0m"
return 1
fi
return 0
Expand Down
4 changes: 2 additions & 2 deletions lib/git/keybindings.sh
Expand Up @@ -28,10 +28,10 @@ if [[ "$git_keyboard_shortcuts_enabled" = "true" ]]; then
if ! set -o | grep -q '^vi .*on$'; then
if [[ $shell == "zsh" ]]; then
_bind "$git_commit_all_keys" " git_commit_all""\n"
_bind "$git_add_and_commit_keys" " \e[1~ git_add_and_commit ""\n"
_bind "$git_add_and_commit_keys" " \033[1~ git_add_and_commit ""\n"
else
_bind "$git_commit_all_keys" "\" git_commit_all\n\""
_bind "$git_add_and_commit_keys" "\"\e[1~ git_add_and_commit \n\""
_bind "$git_add_and_commit_keys" "\"\033[1~ git_add_and_commit \n\""
fi
fi

Expand Down
4 changes: 2 additions & 2 deletions lib/git/shell_shortcuts.sh
Expand Up @@ -126,7 +126,7 @@ function ls_with_file_shortcuts {
fi

if [ "$(echo "$ll_output" | wc -l)" -gt "50" ]; then
echo -e "\e[33mToo many files to create shortcuts. Running plain ll command...\e[0m"
echo -e "\033[33mToo many files to create shortcuts. Running plain ll command...\033[0m"
echo "$ll_output"
return 1
fi
Expand All @@ -138,7 +138,7 @@ e = 1
re = /^(([^ ]* +){8})/
output.lines.each do |line|
next unless line.match(re)
puts line.sub(re, "\\\1\e[2;37m[\e[0m#{e}\e[2;37m]\e[0m" << (e < 10 ? " " : " "))
puts line.sub(re, "\\\1\033[2;37m[\033[0m#{e}\033[2;37m]\033[0m" << (e < 10 ? " " : " "))
e += 1
end
EOF
Expand Down
34 changes: 17 additions & 17 deletions lib/git/status_shortcuts.rb
Expand Up @@ -34,21 +34,21 @@

# Colors
@c = {
:rst => "\e[0m",
:del => "\e[0;31m",
:mod => "\e[0;32m",
:new => "\e[0;33m",
:ren => "\e[0;34m",
:cpy => "\e[0;33m",
:typ => "\e[0;35m",
:unt => "\e[0;36m",
:dark => "\e[2;37m",
:branch => "\e[1m",
:header => "\e[0m"
:rst => "\033[0m",
:del => "\033[0;31m",
:mod => "\033[0;32m",
:new => "\033[0;33m",
:ren => "\033[0;34m",
:cpy => "\033[0;33m",
:typ => "\033[0;35m",
:unt => "\033[0;36m",
:dark => "\033[2;37m",
:branch => "\033[1m",
:header => "\033[0m"
}


# Following colors must be prepended with modifiers e.g. '\e[1;', '\e[0;'
# Following colors must be prepended with modifiers e.g. '\033[1;', '\033[0;'
@group_c = {
:staged => "33m",
:unmerged => "31m",
Expand All @@ -74,7 +74,7 @@

# If no changes, just display green no changes message and exit here
if @git_status == ""
puts "%s#%s On branch: %s#{@branch}#{ahead} %s| \e[0;32mNo changes (working directory clean)%s" % [
puts "%s#%s On branch: %s#{@branch}#{ahead} %s| \033[0;32mNo changes (working directory clean)%s" % [
@c[:dark], @c[:rst], @c[:branch], @c[:dark], @c[:rst]
]
exit
Expand All @@ -99,7 +99,7 @@ def has_modules?
# If changed 'file' is actually a git submodule
if @gitmodules.include?(file)
# Parse long git status for submodule summaries
@git_status_long = `git status`.gsub(/\e\[[^m]*m/, "") # (strip colors)
@git_status_long = `git status`.gsub(/\033\[[^m]*m/, "") # (strip colors)
end
end

Expand Down Expand Up @@ -148,7 +148,7 @@ def relative_path(base, target)
# Output files
def output_file_group(group)
# Print colored hashes & files based on modification groups
c_group = "\e[0;#{@group_c[group]}"
c_group = "\033[0;#{@group_c[group]}"

@stat_hash[group].each do |h|
@e += 1
Expand Down Expand Up @@ -194,8 +194,8 @@ def output_file_group(group)
# Allow filtering by specific group (by string or integer)
if !ARGV[0] || ARGV[0] == group.to_s || ARGV[0] == (i+1).to_s; then
if !@stat_hash[group].empty?
c_arrow="\e[1;#{@group_c[group]}"
c_hash="\e[0;#{@group_c[group]}"
c_arrow="\033[1;#{@group_c[group]}"
c_hash="\033[0;#{@group_c[group]}"
puts "#{c_arrow}#{@c[:header]} #{heading}\n#{c_hash}##{@c[:rst]}"
output_file_group(group)
end
Expand Down
8 changes: 4 additions & 4 deletions lib/git/status_shortcuts.sh
Expand Up @@ -29,7 +29,7 @@ git_status_shortcuts() {
if [[ -z "$cmd_output" ]]; then
# Just show regular git status if ruby script returns nothing.
git status
echo -e "\n\e[33mThere were more than $gs_max_changes changed files. SCM Breeze has fallen back to standard \`git status\` for performance reasons.\e[0m"
echo -e "\n\033[33mThere were more than $gs_max_changes changed files. SCM Breeze has fallen back to standard \`git status\` for performance reasons.\033[0m"
return 1
fi
# Fetch list of files from last line of script output
Expand Down Expand Up @@ -106,7 +106,7 @@ git_show_affected_files(){
for file in $(git show --pretty="format:" --name-only $@ | \grep -v '^$'); do
let f++
export $git_env_char$f=$file # Export numbered variable.
echo -e "# \e[2;37m[\e[0m$f\e[2;37m]\e[0m $file"
echo -e "# \033[2;37m[\033[0m$f\033[2;37m]\033[0m $file"
done; echo "# "
}

Expand Down Expand Up @@ -187,7 +187,7 @@ git_commit_prompt() {
eval $@ # run any prequisite commands
echo $commit_msg | git commit -F - | tail -n +2
else
echo -e "\e[0;31mAborting commit due to empty commit message.\e[0m"
echo -e "\033[0;31mAborting commit due to empty commit message.\033[0m"
fi
escaped=$(echo "$commit_msg" | sed -e 's/"/\\"/g' -e 's/!/"'"'"'!'"'"'"/g')

Expand All @@ -206,7 +206,7 @@ git_commit_all() {
fail_if_not_git_repo || return 1
changes=$(git status --porcelain | wc -l)
if [ "$changes" -gt 0 ]; then
echo -e "\e[0;33mCommitting all files (\e[0;31m$changes\e[0;33m)\e[0m"
echo -e "\033[0;33mCommitting all files (\033[0;31m$changes\033[0;33m)\033[0m"
git_commit_prompt "git add -A"
else
echo "# No changed files to commit."
Expand Down
2 changes: 1 addition & 1 deletion lib/scm_breeze.sh
Expand Up @@ -44,7 +44,7 @@ _create_or_patch_scmbrc() {
cd "$HOME"
# If the patch cannot be applied cleanly, show the updates and tell user to update file manually.
if ! patch -f "$HOME/.$prefix""scmbrc" $patchfile; then
printf "== \e[0;31mUpdates could not be applied to '\e[1m~/.$prefix""scmbrc\e[0;31m'.\e[0m\n"
printf "== \033[0;31mUpdates could not be applied to '\033[1m~/.$prefix""scmbrc\033[0;31m'.\033[0m\n"
printf "== Please look at the following changes and manually update '~/.$prefix""scmbrc', if necessary.\n\n"
cat "$HOME/.$prefix""scmbrc.rej"
fi
Expand Down

0 comments on commit d6730b4

Please sign in to comment.