Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
gitlab-mirrors
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
wonko
gitlab-mirrors
Commits
2313fe6f
Commit
2313fe6f
authored
11 years ago
by
Sam Gleske
Browse files
Options
Downloads
Patches
Plain Diff
Adding colorized output functions
parent
63ae32ac
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
add_mirror.sh
+18
-12
18 additions, 12 deletions
add_mirror.sh
lib/functions.sh
+130
-0
130 additions, 0 deletions
lib/functions.sh
with
148 additions
and
12 deletions
add_mirror.sh
+
18
−
12
View file @
2313fe6f
#!/bin/bash
#!/bin/bash
#Tue Sep 10 23:01:08 EDT 2013
#Tue Sep 10 23:01:08 EDT 2013
#USAGE
#USAGE
# ./add_mirror.sh project
_
name
http://example.com/project.git
# ./add_mirror.sh
--git --
project
-
name
#Include all user options
#Include all user options and dependencies
.
"
$(
dirname
$0
)
/config.sh"
git_mirrors_dir
=
"
$(
dirname
"
${
0
}
"
)
"
.
"
$(
dirname
$0
)
/lib/VERSION"
cd
"
${
git_mirrors_dir
}
"
cd
"
$(
dirname
$0
)
"
.
"config.sh"
.
"lib/VERSION"
.
"lib/functions.sh"
PROGNAME
=
"
${
0
##*/
}
"
PROGNAME
=
"
${
0
##*/
}
"
PROGVERSION
=
"
${
VERSION
}
"
PROGVERSION
=
"
${
VERSION
}
"
#Default script options
#Default script options
svn
=
false
svn
=
false
git
=
false
git
=
false
project_name
=
""
project_name
=
""
mirror
=
""
mirror
=
""
#Short options are one letter. If an argument follows a short opt then put a colon (:) after it
#
SHORTOPTS
=
"hvm:p:"
# ARGUMENT HANDLING
LONGOPTS
=
"help,version,git,svn,mirror:,project:"
#
usage
()
usage
()
{
{
cat
<<
EOF
cat
<<
EOF
...
@@ -44,10 +44,11 @@ DESCRIPTION:
...
@@ -44,10 +44,11 @@ DESCRIPTION:
EOF
EOF
}
}
#Short options are one letter. If an argument follows a short opt then put a colon (:) after it
SHORTOPTS
=
"hvm:p:"
LONGOPTS
=
"help,version,git,svn,mirror:,project:"
ARGS
=
$(
getopt
-s
bash
--options
"
${
SHORTOPTS
}
"
--longoptions
"
${
LONGOPTS
}
"
--name
"
${
PROGNAME
}
"
--
"
$@
"
)
ARGS
=
$(
getopt
-s
bash
--options
"
${
SHORTOPTS
}
"
--longoptions
"
${
LONGOPTS
}
"
--name
"
${
PROGNAME
}
"
--
"
$@
"
)
eval set
--
"
$ARGS
"
eval set
--
"
$ARGS
"
echo
"
$ARGS
"
while
true
;
do
while
true
;
do
case
$1
in
case
$1
in
-h
|
--help
)
-h
|
--help
)
...
@@ -85,6 +86,11 @@ while true; do
...
@@ -85,6 +86,11 @@ while true; do
esac
esac
done
done
function
preflight
()
{
if
${
git
}
&&
${
svn
}
;
then
fi
}
echo
"svn=
${
svn
}
"
echo
"svn=
${
svn
}
"
echo
"git=
${
git
}
"
echo
"git=
${
git
}
"
...
...
This diff is collapsed.
Click to expand it.
lib/functions.sh
0 → 100644
+
130
−
0
View file @
2313fe6f
#COLORS DOCUMENTATION
# black - 30
# red - 31
# green - 32
# brown - 33
# blue - 34
# magenta - 35
# cyan - 36
# lightgray - 37
#
# * 'm' character at the end of each of the following sentences is used as a stop character, where the system should stop and parse the \033[ sintax.
#
# \033[0m - is the default color for the console
# \033[0;#m - is the color of the text, where # is one of the codes mentioned above
# \033[1m - makes text bold
# \033[1;#m - makes colored text bold**
# \033[2;#m - colors text according to # but a bit darker
# \033[4;#m - colors text in # and underlines
# \033[7;#m - colors the background according to #
# \033[9;#m - colors text and strikes it
# \033[A - moves cursor one line above (carfull: it does not erase the previously written line)
# \033[B - moves cursor one line under
# \033[C - moves cursor one spacing to the right
# \033[D - moves cursor one spacing to the left
# \033[E - don't know yet
# \033[F - don't know yet
#
# \033[2K - erases everything written on line before this.
#Colors variables
SETCOLOR_GREEN
=
"echo -en
\\
033[0;32m"
SETCOLOR_RED
=
"echo -en
\\
033[0;31m"
SETCOLOR_YELLOW
=
"echo -en
\\
033[0;33m"
SETCOLOR_NORMAL
=
"echo -en
\\
033[0;39m"
SETSTYLE_BOLD
=
"echo -en
\\
033[1m"
SETSTYLE_UNDERLINE
=
"echo -en
\\
033[4m"
SETSTYLE_NORMAL
=
"echo -en
\\
033[0m"
#same as echo function except the whole text line is red
function
red_echo
()
{
#in order for the -n functionality to work properly $2 must be quoted when called in case of spaces
if
"
${
enable_colors
}
"
;
then
if
[
"
$1
"
=
"-n"
]
;
then
${
SETCOLOR_RED
}
&&
echo
-n
"
$2
"
&&
${
SETCOLOR_NORMAL
}
else
${
SETCOLOR_RED
}
&&
echo
"
$*
"
&&
${
SETCOLOR_NORMAL
}
fi
else
if
[
"
$1
"
=
"-n"
]
;
then
echo
-n
"
$2
"
else
echo
"
$*
"
fi
fi
}
#same as echo function except the whole text line is green
function
green_echo
()
{
#in order for the -n functionality to work properly $2 must be quoted when called in case of spaces
if
"
${
enable_colors
}
"
;
then
if
[
"
$1
"
=
"-n"
]
;
then
${
SETCOLOR_GREEN
}
&&
echo
-n
"
$2
"
&&
${
SETCOLOR_NORMAL
}
else
${
SETCOLOR_GREEN
}
&&
echo
"
$*
"
&&
${
SETCOLOR_NORMAL
}
fi
else
if
[
"
$1
"
=
"-n"
]
;
then
echo
-n
"
$2
"
else
echo
"
$*
"
fi
fi
}
#same as echo function except the whole text line is yellow
function
yellow_echo
()
{
#in order for the -n functionality to work properly $2 must be quoted when called in case of spaces
if
"
${
enable_colors
}
"
;
then
if
[
"
$1
"
=
"-n"
]
;
then
${
SETCOLOR_YELLOW
}
&&
echo
-n
"
$2
"
&&
${
SETCOLOR_NORMAL
}
else
${
SETCOLOR_YELLOW
}
&&
echo
"
$*
"
&&
${
SETCOLOR_NORMAL
}
fi
else
if
[
"
$1
"
=
"-n"
]
;
then
echo
-n
"
$2
"
else
echo
"
$*
"
fi
fi
return
0
}
#same as echo function except output bold text
function
bold_echo
()
{
#in order for the -n functionality to work properly $2 must be quoted when called in case of spaces
if
"
${
enable_colors
}
"
;
then
if
[
"
$1
"
=
"-n"
]
;
then
${
SETSTYLE_BOLD
}
&&
echo
-n
"
$2
"
&&
${
SETSTYLE_NORMAL
}
else
${
SETSTYLE_BOLD
}
&&
echo
"
$*
"
&&
${
SETSTYLE_NORMAL
}
fi
else
if
[
"
$1
"
=
"-n"
]
;
then
echo
-n
"
$2
"
else
echo
"
$*
"
fi
fi
return
0
}
#same as echo function except output underlined text
function
underline_echo
()
{
#in order for the -n functionality to work properly $2 must be quoted when called in case of spaces
if
"
${
enable_colors
}
"
;
then
if
[
"
$1
"
=
"-n"
]
;
then
${
SETSTYLE_UNDERLINE
}
&&
echo
-n
"
$2
"
&&
${
SETSTYLE_NORMAL
}
else
${
SETSTYLE_UNDERLINE
}
&&
echo
"
$*
"
&&
${
SETSTYLE_NORMAL
}
fi
else
if
[
"
$1
"
=
"-n"
]
;
then
echo
-n
"
$2
"
else
echo
"
$*
"
fi
fi
return
0
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment