confinicky 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +6 -3
- data/bin/cfy +18 -1
- data/confinicky.gemspec +8 -8
- data/lib/confinicky/shell_file.rb +19 -5
- data/lib/confinicky/version.rb +10 -0
- data/test/helper.rb +1 -2
- data/test/sample_bash_file.sh +652 -0
- data/test/test_confinicky.rb +15 -3
- data/test/test_file_writing.rb +41 -0
- metadata +6 -6
- data/VERSION +0 -1
- data/bin/confinicky +0 -5
- data/lib/confinicky/boot.rb +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 53f1baf258a65df2bcf011c06047e10b3cbbab80
|
4
|
+
data.tar.gz: 55b8320db2def454e6fd80bc9432e26bcef04788
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bbeccd3fda8048b6e9d2797e7fbefccc4e6f817c6c6748d6e85034f5628fd51339e53dd189ca8a4c41aa77530e8e0086d85015dc9a245cbf7c1be1ca55e9bfb6
|
7
|
+
data.tar.gz: 0c07f1a3af6b25078b7e705d0f297af9147afc1f70dc604ee52c47554f67b60e2784da4695224278a20bebac7793d115b8f996bd9a66913007b7695bc8f659f7
|
data/Rakefile
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
require 'rubygems'
|
4
4
|
require 'bundler'
|
5
|
+
require './lib/confinicky/version.rb'
|
6
|
+
|
5
7
|
begin
|
6
8
|
Bundler.setup(:default, :development)
|
7
9
|
rescue Bundler::BundlerError => e
|
@@ -18,10 +20,11 @@ Jeweler::Tasks.new do |gem|
|
|
18
20
|
gem.homepage = "http://github.com/jimjeffers/confinicky"
|
19
21
|
gem.license = "MIT"
|
20
22
|
gem.summary = "A simple CLI to manage environment variables on your local machine."
|
21
|
-
gem.description = "A CLI
|
23
|
+
gem.description = "A simple CLI to manage environment variables on your local machine. Perform basic CRUD for your environment variables all in the command line."
|
22
24
|
gem.email = "jim@sumocreations.com"
|
23
25
|
gem.authors = ["Jim Jeffers"]
|
24
|
-
gem.executables = ['
|
26
|
+
gem.executables = ['cfy']
|
27
|
+
gem.version = Confinicky::Version::STRING
|
25
28
|
# dependencies defined in Gemfile
|
26
29
|
end
|
27
30
|
Jeweler::RubygemsDotOrgTasks.new
|
@@ -43,7 +46,7 @@ task :default => :test
|
|
43
46
|
|
44
47
|
require 'rdoc/task'
|
45
48
|
Rake::RDocTask.new do |rdoc|
|
46
|
-
version =
|
49
|
+
version = Confinicky::Version::STRING
|
47
50
|
|
48
51
|
rdoc.rdoc_dir = 'rdoc'
|
49
52
|
rdoc.title = "confinicky #{version}"
|
data/bin/cfy
CHANGED
@@ -2,4 +2,21 @@
|
|
2
2
|
|
3
3
|
$:.push File.expand_path("../../lib", __FILE__)
|
4
4
|
|
5
|
-
require '
|
5
|
+
require 'commander/import'
|
6
|
+
require 'terminal-table'
|
7
|
+
require 'confinicky'
|
8
|
+
|
9
|
+
HighLine.track_eof = false # Fix for built-in Ruby
|
10
|
+
Signal.trap("INT") {} # Suppress backtrace when exiting command
|
11
|
+
|
12
|
+
program :name, "Confinicky"
|
13
|
+
program :version, Confinicky::Version::STRING
|
14
|
+
program :description, 'A command-line interface for managing your shell environment variables.'
|
15
|
+
|
16
|
+
program :help, 'Author', 'Jim Jeffers <jim@sumocreations.com>'
|
17
|
+
program :help, 'Website', 'https://github.com/jimjeffers'
|
18
|
+
program :help_formatter, :compact
|
19
|
+
|
20
|
+
default_command :help
|
21
|
+
|
22
|
+
require 'confinicky/commands'
|
data/confinicky.gemspec
CHANGED
@@ -2,19 +2,19 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: confinicky 0.1.
|
5
|
+
# stub: confinicky 0.1.5 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "confinicky"
|
9
|
-
s.version = "0.1.
|
9
|
+
s.version = "0.1.5"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Jim Jeffers"]
|
14
14
|
s.date = "2014-08-11"
|
15
|
-
s.description = "A CLI
|
15
|
+
s.description = "A simple CLI to manage environment variables on your local machine. Perform basic CRUD for your environment variables all in the command line."
|
16
16
|
s.email = "jim@sumocreations.com"
|
17
|
-
s.executables = ["
|
17
|
+
s.executables = ["cfy"]
|
18
18
|
s.extra_rdoc_files = [
|
19
19
|
"LICENSE.txt",
|
20
20
|
"README.rdoc"
|
@@ -26,12 +26,9 @@ Gem::Specification.new do |s|
|
|
26
26
|
"LICENSE.txt",
|
27
27
|
"README.rdoc",
|
28
28
|
"Rakefile",
|
29
|
-
"VERSION",
|
30
29
|
"bin/cfy",
|
31
|
-
"bin/confinicky",
|
32
30
|
"confinicky.gemspec",
|
33
31
|
"lib/confinicky.rb",
|
34
|
-
"lib/confinicky/boot.rb",
|
35
32
|
"lib/confinicky/commands.rb",
|
36
33
|
"lib/confinicky/commands/clean.rb",
|
37
34
|
"lib/confinicky/commands/duplicates.rb",
|
@@ -41,8 +38,11 @@ Gem::Specification.new do |s|
|
|
41
38
|
"lib/confinicky/commands/use.rb",
|
42
39
|
"lib/confinicky/config.rb",
|
43
40
|
"lib/confinicky/shell_file.rb",
|
41
|
+
"lib/confinicky/version.rb",
|
44
42
|
"test/helper.rb",
|
45
|
-
"test/
|
43
|
+
"test/sample_bash_file.sh",
|
44
|
+
"test/test_confinicky.rb",
|
45
|
+
"test/test_file_writing.rb"
|
46
46
|
]
|
47
47
|
s.homepage = "http://github.com/jimjeffers/confinicky"
|
48
48
|
s.licenses = ["MIT"]
|
@@ -3,6 +3,8 @@ require 'fileutils'
|
|
3
3
|
module Confinicky
|
4
4
|
class ShellFile
|
5
5
|
|
6
|
+
attr_reader :lines
|
7
|
+
attr_reader :exports
|
6
8
|
##
|
7
9
|
# References the actual file path from the shell configuration.
|
8
10
|
def self.file_path
|
@@ -31,16 +33,21 @@ module Confinicky
|
|
31
33
|
|
32
34
|
##
|
33
35
|
# Parses the configuration file if it exists.
|
34
|
-
def initialize
|
35
|
-
raise "Config file not found. Please set" if !
|
36
|
+
def initialize(file_path: Confinicky::ShellFile.file_path)
|
37
|
+
raise "Config file not found. Please set" if !File.exists?(@file_path = file_path)
|
36
38
|
@exports = []
|
37
39
|
@lines = []
|
38
|
-
|
40
|
+
|
41
|
+
file = File.new(@file_path, "r")
|
39
42
|
|
40
43
|
while (line = file.gets)
|
41
44
|
if line =~ /\Aexport /
|
42
45
|
export = line.gsub(/\Aexport /,"").split("=")
|
43
|
-
|
46
|
+
if export[1].nil?
|
47
|
+
@lines << line
|
48
|
+
else
|
49
|
+
@exports << [export[0], export[1].gsub(/\n/, "")]
|
50
|
+
end
|
44
51
|
else
|
45
52
|
@lines << line
|
46
53
|
end
|
@@ -83,6 +90,7 @@ module Confinicky
|
|
83
90
|
assignment = assignment.split("=")
|
84
91
|
return false if assignment.length < 2
|
85
92
|
remove! assignment[0]
|
93
|
+
assignment[1] = "\'#{assignment[1]}\'" if assignment[1] =~ /\s/
|
86
94
|
@exports << assignment
|
87
95
|
end
|
88
96
|
|
@@ -95,7 +103,7 @@ module Confinicky
|
|
95
103
|
##
|
96
104
|
# Writes a new version of the configuration file.
|
97
105
|
def write!
|
98
|
-
File.open(
|
106
|
+
File.open(@file_path, "w") do |f|
|
99
107
|
for line in @lines
|
100
108
|
f.write line
|
101
109
|
end
|
@@ -103,5 +111,11 @@ module Confinicky
|
|
103
111
|
end
|
104
112
|
end
|
105
113
|
|
114
|
+
##
|
115
|
+
# Returns the file path for the current instance of the shell file class.
|
116
|
+
def file_path
|
117
|
+
@file_path
|
118
|
+
end
|
119
|
+
|
106
120
|
end
|
107
121
|
end
|
data/test/helper.rb
CHANGED
@@ -24,14 +24,13 @@ rescue Bundler::BundlerError => e
|
|
24
24
|
exit e.status_code
|
25
25
|
end
|
26
26
|
|
27
|
-
gem "minitest"
|
28
27
|
require 'minitest/autorun'
|
29
28
|
|
30
29
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
31
30
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
32
31
|
require 'confinicky'
|
33
32
|
|
34
|
-
class MiniTest::
|
33
|
+
class MiniTest::Test
|
35
34
|
end
|
36
35
|
|
37
36
|
MiniTest.autorun
|
@@ -0,0 +1,652 @@
|
|
1
|
+
# =============================================================== #
|
2
|
+
#
|
3
|
+
# PERSONAL $HOME/.bashrc FILE for bash-3.0 (or later)
|
4
|
+
# By Emmanuel Rouat [no-email]
|
5
|
+
#
|
6
|
+
# Last modified: Tue Nov 20 22:04:47 CET 2012
|
7
|
+
|
8
|
+
# This file is normally read by interactive shells only.
|
9
|
+
#+ Here is the place to define your aliases, functions and
|
10
|
+
#+ other interactive features like your prompt.
|
11
|
+
#
|
12
|
+
# The majority of the code here assumes you are on a GNU
|
13
|
+
#+ system (most likely a Linux box) and is often based on code
|
14
|
+
#+ found on Usenet or Internet.
|
15
|
+
#
|
16
|
+
# See for instance:
|
17
|
+
# http://tldp.org/LDP/abs/html/index.html
|
18
|
+
# http://www.caliban.org/bash
|
19
|
+
# http://www.shelldorado.com/scripts/categories.html
|
20
|
+
# http://www.dotfiles.org
|
21
|
+
#
|
22
|
+
# The choice of colors was done for a shell with a dark background
|
23
|
+
#+ (white on black), and this is usually also suited for pure text-mode
|
24
|
+
#+ consoles (no X server available). If you use a white background,
|
25
|
+
#+ you'll have to do some other choices for readability.
|
26
|
+
#
|
27
|
+
# This bashrc file is a bit overcrowded.
|
28
|
+
# Remember, it is just just an example.
|
29
|
+
# Tailor it to your needs.
|
30
|
+
#
|
31
|
+
# =============================================================== #
|
32
|
+
|
33
|
+
# --> Comments added by HOWTO author.
|
34
|
+
|
35
|
+
# If not running interactively, don't do anything
|
36
|
+
[ -z "$PS1" ] && return
|
37
|
+
|
38
|
+
|
39
|
+
#-------------------------------------------------------------
|
40
|
+
# Source global definitions (if any)
|
41
|
+
#-------------------------------------------------------------
|
42
|
+
|
43
|
+
|
44
|
+
if [ -f /etc/bashrc ]; then
|
45
|
+
. /etc/bashrc # --> Read /etc/bashrc, if present.
|
46
|
+
fi
|
47
|
+
|
48
|
+
|
49
|
+
#--------------------------------------------------------------
|
50
|
+
# Automatic setting of $DISPLAY (if not set already).
|
51
|
+
# This works for me - your mileage may vary. . . .
|
52
|
+
# The problem is that different types of terminals give
|
53
|
+
#+ different answers to 'who am i' (rxvt in particular can be
|
54
|
+
#+ troublesome) - however this code seems to work in a majority
|
55
|
+
#+ of cases.
|
56
|
+
#--------------------------------------------------------------
|
57
|
+
|
58
|
+
function get_xserver ()
|
59
|
+
{
|
60
|
+
case $TERM in
|
61
|
+
xterm )
|
62
|
+
XSERVER=$(who am i | awk '{print $NF}' | tr -d ')''(' )
|
63
|
+
# Ane-Pieter Wieringa suggests the following alternative:
|
64
|
+
# I_AM=$(who am i)
|
65
|
+
# SERVER=${I_AM#*(}
|
66
|
+
# SERVER=${SERVER%*)}
|
67
|
+
XSERVER=${XSERVER%%:*}
|
68
|
+
;;
|
69
|
+
aterm | rxvt)
|
70
|
+
# Find some code that works here. ...
|
71
|
+
;;
|
72
|
+
esac
|
73
|
+
}
|
74
|
+
|
75
|
+
if [ -z ${DISPLAY:=""} ]; then
|
76
|
+
get_xserver
|
77
|
+
if [[ -z ${XSERVER} || ${XSERVER} == $(hostname) ||
|
78
|
+
${XSERVER} == "unix" ]]; then
|
79
|
+
DISPLAY=":0.0" # Display on local host.
|
80
|
+
else
|
81
|
+
DISPLAY=${XSERVER}:0.0 # Display on remote host.
|
82
|
+
fi
|
83
|
+
fi
|
84
|
+
|
85
|
+
export DISPLAY
|
86
|
+
|
87
|
+
#-------------------------------------------------------------
|
88
|
+
# Some settings
|
89
|
+
#-------------------------------------------------------------
|
90
|
+
|
91
|
+
#set -o nounset # These two options are useful for debugging.
|
92
|
+
#set -o xtrace
|
93
|
+
alias debug="set -o nounset; set -o xtrace"
|
94
|
+
|
95
|
+
ulimit -S -c 0 # Don't want coredumps.
|
96
|
+
set -o notify
|
97
|
+
set -o noclobber
|
98
|
+
set -o ignoreeof
|
99
|
+
|
100
|
+
|
101
|
+
# Enable options:
|
102
|
+
shopt -s cdspell
|
103
|
+
shopt -s cdable_vars
|
104
|
+
shopt -s checkhash
|
105
|
+
shopt -s checkwinsize
|
106
|
+
shopt -s sourcepath
|
107
|
+
shopt -s no_empty_cmd_completion
|
108
|
+
shopt -s cmdhist
|
109
|
+
shopt -s histappend histreedit histverify
|
110
|
+
shopt -s extglob # Necessary for programmable completion.
|
111
|
+
|
112
|
+
# Disable options:
|
113
|
+
shopt -u mailwarn
|
114
|
+
unset MAILCHECK # Don't want my shell to warn me of incoming mail.
|
115
|
+
|
116
|
+
|
117
|
+
#-------------------------------------------------------------
|
118
|
+
# Greeting, motd etc. ...
|
119
|
+
#-------------------------------------------------------------
|
120
|
+
|
121
|
+
# Color definitions (taken from Color Bash Prompt HowTo).
|
122
|
+
# Some colors might look different of some terminals.
|
123
|
+
# For example, I see 'Bold Red' as 'orange' on my screen,
|
124
|
+
# hence the 'Green' 'BRed' 'Red' sequence I often use in my prompt.
|
125
|
+
|
126
|
+
|
127
|
+
# Normal Colors
|
128
|
+
Black='\e[0;30m' # Black
|
129
|
+
Red='\e[0;31m' # Red
|
130
|
+
Green='\e[0;32m' # Green
|
131
|
+
Yellow='\e[0;33m' # Yellow
|
132
|
+
Blue='\e[0;34m' # Blue
|
133
|
+
Purple='\e[0;35m' # Purple
|
134
|
+
Cyan='\e[0;36m' # Cyan
|
135
|
+
White='\e[0;37m' # White
|
136
|
+
|
137
|
+
# Bold
|
138
|
+
BBlack='\e[1;30m' # Black
|
139
|
+
BRed='\e[1;31m' # Red
|
140
|
+
BGreen='\e[1;32m' # Green
|
141
|
+
BYellow='\e[1;33m' # Yellow
|
142
|
+
BBlue='\e[1;34m' # Blue
|
143
|
+
BPurple='\e[1;35m' # Purple
|
144
|
+
BCyan='\e[1;36m' # Cyan
|
145
|
+
BWhite='\e[1;37m' # White
|
146
|
+
|
147
|
+
# Background
|
148
|
+
On_Black='\e[40m' # Black
|
149
|
+
On_Red='\e[41m' # Red
|
150
|
+
On_Green='\e[42m' # Green
|
151
|
+
On_Yellow='\e[43m' # Yellow
|
152
|
+
On_Blue='\e[44m' # Blue
|
153
|
+
On_Purple='\e[45m' # Purple
|
154
|
+
On_Cyan='\e[46m' # Cyan
|
155
|
+
On_White='\e[47m' # White
|
156
|
+
|
157
|
+
NC="\e[m" # Color Reset
|
158
|
+
|
159
|
+
|
160
|
+
ALERT=${BWhite}${On_Red} # Bold White on red background
|
161
|
+
|
162
|
+
|
163
|
+
|
164
|
+
echo -e "${BCyan}This is BASH ${BRed}${BASH_VERSION%.*}${BCyan}\
|
165
|
+
- DISPLAY on ${BRed}$DISPLAY${NC}\n"
|
166
|
+
date
|
167
|
+
if [ -x /usr/games/fortune ]; then
|
168
|
+
/usr/games/fortune -s # Makes our day a bit more fun.... :-)
|
169
|
+
fi
|
170
|
+
|
171
|
+
function _exit() # Function to run upon exit of shell.
|
172
|
+
{
|
173
|
+
echo -e "${BRed}Hasta la vista, baby${NC}"
|
174
|
+
}
|
175
|
+
trap _exit EXIT
|
176
|
+
|
177
|
+
#-------------------------------------------------------------
|
178
|
+
# Shell Prompt - for many examples, see:
|
179
|
+
# http://www.debian-administration.org/articles/205
|
180
|
+
# http://www.askapache.com/linux/bash-power-prompt.html
|
181
|
+
# http://tldp.org/HOWTO/Bash-Prompt-HOWTO
|
182
|
+
# https://github.com/nojhan/liquidprompt
|
183
|
+
#-------------------------------------------------------------
|
184
|
+
# Current Format: [TIME USER@HOST PWD] >
|
185
|
+
# TIME:
|
186
|
+
# Green == machine load is low
|
187
|
+
# Orange == machine load is medium
|
188
|
+
# Red == machine load is high
|
189
|
+
# ALERT == machine load is very high
|
190
|
+
# USER:
|
191
|
+
# Cyan == normal user
|
192
|
+
# Orange == SU to user
|
193
|
+
# Red == root
|
194
|
+
# HOST:
|
195
|
+
# Cyan == local session
|
196
|
+
# Green == secured remote connection (via ssh)
|
197
|
+
# Red == unsecured remote connection
|
198
|
+
# PWD:
|
199
|
+
# Green == more than 10% free disk space
|
200
|
+
# Orange == less than 10% free disk space
|
201
|
+
# ALERT == less than 5% free disk space
|
202
|
+
# Red == current user does not have write privileges
|
203
|
+
# Cyan == current filesystem is size zero (like /proc)
|
204
|
+
# >:
|
205
|
+
# White == no background or suspended jobs in this shell
|
206
|
+
# Cyan == at least one background job in this shell
|
207
|
+
# Orange == at least one suspended job in this shell
|
208
|
+
#
|
209
|
+
# Command is added to the history file each time you hit enter,
|
210
|
+
# so it's available to all shells (using 'history -a').
|
211
|
+
|
212
|
+
|
213
|
+
# Test connection type:
|
214
|
+
if [ -n "${SSH_CONNECTION}" ]; then
|
215
|
+
CNX=${Green} # Connected on remote machine, via ssh (good).
|
216
|
+
elif [[ "${DISPLAY%%:0*}" != "" ]]; then
|
217
|
+
CNX=${ALERT} # Connected on remote machine, not via ssh (bad).
|
218
|
+
else
|
219
|
+
CNX=${BCyan} # Connected on local machine.
|
220
|
+
fi
|
221
|
+
|
222
|
+
# Test user type:
|
223
|
+
if [[ ${USER} == "root" ]]; then
|
224
|
+
SU=${Red} # User is root.
|
225
|
+
elif [[ ${USER} != $(logname) ]]; then
|
226
|
+
SU=${BRed} # User is not login user.
|
227
|
+
else
|
228
|
+
SU=${BCyan} # User is normal (well ... most of us are).
|
229
|
+
fi
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
NCPU=$(grep -c 'processor' /proc/cpuinfo) # Number of CPUs
|
234
|
+
SLOAD=$(( 100*${NCPU} )) # Small load
|
235
|
+
MLOAD=$(( 200*${NCPU} )) # Medium load
|
236
|
+
XLOAD=$(( 400*${NCPU} )) # Xlarge load
|
237
|
+
|
238
|
+
# Returns system load as percentage, i.e., '40' rather than '0.40)'.
|
239
|
+
function load()
|
240
|
+
{
|
241
|
+
local SYSLOAD=$(cut -d " " -f1 /proc/loadavg | tr -d '.')
|
242
|
+
# System load of the current host.
|
243
|
+
echo $((10#$SYSLOAD)) # Convert to decimal.
|
244
|
+
}
|
245
|
+
|
246
|
+
# Returns a color indicating system load.
|
247
|
+
function load_color()
|
248
|
+
{
|
249
|
+
local SYSLOAD=$(load)
|
250
|
+
if [ ${SYSLOAD} -gt ${XLOAD} ]; then
|
251
|
+
echo -en ${ALERT}
|
252
|
+
elif [ ${SYSLOAD} -gt ${MLOAD} ]; then
|
253
|
+
echo -en ${Red}
|
254
|
+
elif [ ${SYSLOAD} -gt ${SLOAD} ]; then
|
255
|
+
echo -en ${BRed}
|
256
|
+
else
|
257
|
+
echo -en ${Green}
|
258
|
+
fi
|
259
|
+
}
|
260
|
+
|
261
|
+
# Returns a color according to free disk space in $PWD.
|
262
|
+
function disk_color()
|
263
|
+
{
|
264
|
+
if [ ! -w "${PWD}" ] ; then
|
265
|
+
echo -en ${Red}
|
266
|
+
# No 'write' privilege in the current directory.
|
267
|
+
elif [ -s "${PWD}" ] ; then
|
268
|
+
local used=$(command df -P "$PWD" |
|
269
|
+
awk 'END {print $5} {sub(/%/,"")}')
|
270
|
+
if [ ${used} -gt 95 ]; then
|
271
|
+
echo -en ${ALERT} # Disk almost full (>95%).
|
272
|
+
elif [ ${used} -gt 90 ]; then
|
273
|
+
echo -en ${BRed} # Free disk space almost gone.
|
274
|
+
else
|
275
|
+
echo -en ${Green} # Free disk space is ok.
|
276
|
+
fi
|
277
|
+
else
|
278
|
+
echo -en ${Cyan}
|
279
|
+
# Current directory is size '0' (like /proc, /sys etc).
|
280
|
+
fi
|
281
|
+
}
|
282
|
+
|
283
|
+
# Returns a color according to running/suspended jobs.
|
284
|
+
function job_color()
|
285
|
+
{
|
286
|
+
if [ $(jobs -s | wc -l) -gt "0" ]; then
|
287
|
+
echo -en ${BRed}
|
288
|
+
elif [ $(jobs -r | wc -l) -gt "0" ] ; then
|
289
|
+
echo -en ${BCyan}
|
290
|
+
fi
|
291
|
+
}
|
292
|
+
|
293
|
+
# Adds some text in the terminal frame (if applicable).
|
294
|
+
|
295
|
+
|
296
|
+
# Now we construct the prompt.
|
297
|
+
PROMPT_COMMAND="history -a"
|
298
|
+
case ${TERM} in
|
299
|
+
*term | rxvt | linux)
|
300
|
+
PS1="\[\$(load_color)\][\A\[${NC}\] "
|
301
|
+
# Time of day (with load info):
|
302
|
+
PS1="\[\$(load_color)\][\A\[${NC}\] "
|
303
|
+
# User@Host (with connection type info):
|
304
|
+
PS1=${PS1}"\[${SU}\]\u\[${NC}\]@\[${CNX}\]\h\[${NC}\] "
|
305
|
+
# PWD (with 'disk space' info):
|
306
|
+
PS1=${PS1}"\[\$(disk_color)\]\W]\[${NC}\] "
|
307
|
+
# Prompt (with 'job' info):
|
308
|
+
PS1=${PS1}"\[\$(job_color)\]>\[${NC}\] "
|
309
|
+
# Set title of current xterm:
|
310
|
+
PS1=${PS1}"\[\e]0;[\u@\h] \w\a\]"
|
311
|
+
;;
|
312
|
+
*)
|
313
|
+
PS1="(\A \u@\h \W) > " # --> PS1="(\A \u@\h \w) > "
|
314
|
+
# --> Shows full pathname of current dir.
|
315
|
+
;;
|
316
|
+
esac
|
317
|
+
|
318
|
+
|
319
|
+
|
320
|
+
export TIMEFORMAT=$'\nreal %3R\tuser %3U\tsys %3S\tpcpu %P\n'
|
321
|
+
export HISTIGNORE="&:bg:fg:ll:h"
|
322
|
+
export HISTTIMEFORMAT="$(echo -e ${BCyan})[%d/%m %H:%M:%S]$(echo -e ${NC}) "
|
323
|
+
export HISTCONTROL=ignoredups
|
324
|
+
export HOSTFILE=$HOME/.hosts # Put a list of remote hosts in ~/.hosts
|
325
|
+
|
326
|
+
|
327
|
+
#============================================================
|
328
|
+
#
|
329
|
+
# ALIASES AND FUNCTIONS
|
330
|
+
#
|
331
|
+
# Arguably, some functions defined here are quite big.
|
332
|
+
# If you want to make this file smaller, these functions can
|
333
|
+
#+ be converted into scripts and removed from here.
|
334
|
+
#
|
335
|
+
#============================================================
|
336
|
+
|
337
|
+
#-------------------
|
338
|
+
# Personnal Aliases
|
339
|
+
#-------------------
|
340
|
+
|
341
|
+
alias rm='rm -i'
|
342
|
+
alias cp='cp -i'
|
343
|
+
alias mv='mv -i'
|
344
|
+
# -> Prevents accidentally clobbering files.
|
345
|
+
alias mkdir='mkdir -p'
|
346
|
+
|
347
|
+
alias h='history'
|
348
|
+
alias j='jobs -l'
|
349
|
+
alias which='type -a'
|
350
|
+
alias ..='cd ..'
|
351
|
+
|
352
|
+
# Pretty-print of some PATH variables:
|
353
|
+
alias path='echo -e ${PATH//:/\\n}'
|
354
|
+
alias libpath='echo -e ${LD_LIBRARY_PATH//:/\\n}'
|
355
|
+
|
356
|
+
|
357
|
+
alias du='du -kh' # Makes a more readable output.
|
358
|
+
alias df='df -kTh'
|
359
|
+
|
360
|
+
#-------------------------------------------------------------
|
361
|
+
# The 'ls' family (this assumes you use a recent GNU ls).
|
362
|
+
#-------------------------------------------------------------
|
363
|
+
# Add colors for filetype and human-readable sizes by default on 'ls':
|
364
|
+
alias ls='ls -h --color'
|
365
|
+
alias lx='ls -lXB' # Sort by extension.
|
366
|
+
alias lk='ls -lSr' # Sort by size, biggest last.
|
367
|
+
alias lt='ls -ltr' # Sort by date, most recent last.
|
368
|
+
alias lc='ls -ltcr' # Sort by/show change time,most recent last.
|
369
|
+
alias lu='ls -ltur' # Sort by/show access time,most recent last.
|
370
|
+
|
371
|
+
# The ubiquitous 'll': directories first, with alphanumeric sorting:
|
372
|
+
alias ll="ls -lv --group-directories-first"
|
373
|
+
alias lm='ll |more' # Pipe through 'more'
|
374
|
+
alias lr='ll -R' # Recursive ls.
|
375
|
+
alias la='ll -A' # Show hidden files.
|
376
|
+
alias tree='tree -Csuh' # Nice alternative to 'recursive ls' ...
|
377
|
+
|
378
|
+
|
379
|
+
#-------------------------------------------------------------
|
380
|
+
# Tailoring 'less'
|
381
|
+
#-------------------------------------------------------------
|
382
|
+
|
383
|
+
alias more='less'
|
384
|
+
export PAGER=less
|
385
|
+
export LESSCHARSET='latin1'
|
386
|
+
export LESSOPEN='|/usr/bin/lesspipe.sh %s 2>&-'
|
387
|
+
# Use this if lesspipe.sh exists.
|
388
|
+
export LESS='-i -N -w -z-4 -g -e -M -X -F -R -P%t?f%f \
|
389
|
+
:stdin .?pb%pb\%:?lbLine %lb:?bbByte %bb:-...'
|
390
|
+
|
391
|
+
# LESS man page colors (makes Man pages more readable).
|
392
|
+
export LESS_TERMCAP_mb=$'\E[01;31m'
|
393
|
+
export LESS_TERMCAP_md=$'\E[01;31m'
|
394
|
+
export LESS_TERMCAP_me=$'\E[0m'
|
395
|
+
export LESS_TERMCAP_se=$'\E[0m'
|
396
|
+
export LESS_TERMCAP_so=$'\E[01;44;33m'
|
397
|
+
export LESS_TERMCAP_ue=$'\E[0m'
|
398
|
+
export LESS_TERMCAP_us=$'\E[01;32m'
|
399
|
+
|
400
|
+
|
401
|
+
#-------------------------------------------------------------
|
402
|
+
# Spelling typos - highly personnal and keyboard-dependent :-)
|
403
|
+
#-------------------------------------------------------------
|
404
|
+
|
405
|
+
alias xs='cd'
|
406
|
+
alias vf='cd'
|
407
|
+
alias moer='more'
|
408
|
+
alias moew='more'
|
409
|
+
alias kk='ll'
|
410
|
+
|
411
|
+
|
412
|
+
#-------------------------------------------------------------
|
413
|
+
# A few fun ones
|
414
|
+
#-------------------------------------------------------------
|
415
|
+
|
416
|
+
# Adds some text in the terminal frame (if applicable).
|
417
|
+
|
418
|
+
function xtitle()
|
419
|
+
{
|
420
|
+
case "$TERM" in
|
421
|
+
*term* | rxvt)
|
422
|
+
echo -en "\e]0;$*\a" ;;
|
423
|
+
*) ;;
|
424
|
+
esac
|
425
|
+
}
|
426
|
+
|
427
|
+
|
428
|
+
# Aliases that use xtitle
|
429
|
+
alias top='xtitle Processes on $HOST && top'
|
430
|
+
alias make='xtitle Making $(basename $PWD) ; make'
|
431
|
+
|
432
|
+
# .. and functions
|
433
|
+
function man()
|
434
|
+
{
|
435
|
+
for i ; do
|
436
|
+
xtitle The $(basename $1|tr -d .[:digit:]) manual
|
437
|
+
command man -a "$i"
|
438
|
+
done
|
439
|
+
}
|
440
|
+
|
441
|
+
|
442
|
+
#-------------------------------------------------------------
|
443
|
+
# Make the following commands run in background automatically:
|
444
|
+
#-------------------------------------------------------------
|
445
|
+
|
446
|
+
function te() # wrapper around xemacs/gnuserv
|
447
|
+
{
|
448
|
+
if [ "$(gnuclient -batch -eval t 2>&-)" == "t" ]; then
|
449
|
+
gnuclient -q "$@";
|
450
|
+
else
|
451
|
+
( xemacs "$@" &);
|
452
|
+
fi
|
453
|
+
}
|
454
|
+
|
455
|
+
function soffice() { command soffice "$@" & }
|
456
|
+
function firefox() { command firefox "$@" & }
|
457
|
+
function xpdf() { command xpdf "$@" & }
|
458
|
+
|
459
|
+
|
460
|
+
#-------------------------------------------------------------
|
461
|
+
# File & strings related functions:
|
462
|
+
#-------------------------------------------------------------
|
463
|
+
|
464
|
+
|
465
|
+
# Find a file with a pattern in name:
|
466
|
+
function ff() { find . -type f -iname '*'"$*"'*' -ls ; }
|
467
|
+
|
468
|
+
# Find a file with pattern $1 in name and Execute $2 on it:
|
469
|
+
function fe() { find . -type f -iname '*'"${1:-}"'*' \
|
470
|
+
-exec ${2:-file} {} \; ; }
|
471
|
+
|
472
|
+
# Find a pattern in a set of files and highlight them:
|
473
|
+
#+ (needs a recent version of egrep).
|
474
|
+
function fstr()
|
475
|
+
{
|
476
|
+
OPTIND=1
|
477
|
+
local mycase=""
|
478
|
+
local usage="fstr: find string in files.
|
479
|
+
Usage: fstr [-i] \"pattern\" [\"filename pattern\"] "
|
480
|
+
while getopts :it opt
|
481
|
+
do
|
482
|
+
case "$opt" in
|
483
|
+
i) mycase="-i " ;;
|
484
|
+
*) echo "$usage"; return ;;
|
485
|
+
esac
|
486
|
+
done
|
487
|
+
shift $(( $OPTIND - 1 ))
|
488
|
+
if [ "$#" -lt 1 ]; then
|
489
|
+
echo "$usage"
|
490
|
+
return;
|
491
|
+
fi
|
492
|
+
find . -type f -name "${2:-*}" -print0 | \
|
493
|
+
xargs -0 egrep --color=always -sn ${case} "$1" 2>&- | more
|
494
|
+
|
495
|
+
}
|
496
|
+
|
497
|
+
|
498
|
+
function swap()
|
499
|
+
{ # Swap 2 filenames around, if they exist (from Uzi's bashrc).
|
500
|
+
local TMPFILE=tmp.$$
|
501
|
+
|
502
|
+
[ $# -ne 2 ] && echo "swap: 2 arguments needed" && return 1
|
503
|
+
[ ! -e $1 ] && echo "swap: $1 does not exist" && return 1
|
504
|
+
[ ! -e $2 ] && echo "swap: $2 does not exist" && return 1
|
505
|
+
|
506
|
+
mv "$1" $TMPFILE
|
507
|
+
mv "$2" "$1"
|
508
|
+
mv $TMPFILE "$2"
|
509
|
+
}
|
510
|
+
|
511
|
+
function extract() # Handy Extract Program
|
512
|
+
{
|
513
|
+
if [ -f $1 ] ; then
|
514
|
+
case $1 in
|
515
|
+
*.tar.bz2) tar xvjf $1 ;;
|
516
|
+
*.tar.gz) tar xvzf $1 ;;
|
517
|
+
*.bz2) bunzip2 $1 ;;
|
518
|
+
*.rar) unrar x $1 ;;
|
519
|
+
*.gz) gunzip $1 ;;
|
520
|
+
*.tar) tar xvf $1 ;;
|
521
|
+
*.tbz2) tar xvjf $1 ;;
|
522
|
+
*.tgz) tar xvzf $1 ;;
|
523
|
+
*.zip) unzip $1 ;;
|
524
|
+
*.Z) uncompress $1 ;;
|
525
|
+
*.7z) 7z x $1 ;;
|
526
|
+
*) echo "'$1' cannot be extracted via >extract<" ;;
|
527
|
+
esac
|
528
|
+
else
|
529
|
+
echo "'$1' is not a valid file!"
|
530
|
+
fi
|
531
|
+
}
|
532
|
+
|
533
|
+
|
534
|
+
# Creates an archive (*.tar.gz) from given directory.
|
535
|
+
function maketar() { tar cvzf "${1%%/}.tar.gz" "${1%%/}/"; }
|
536
|
+
|
537
|
+
# Create a ZIP archive of a file or folder.
|
538
|
+
function makezip() { zip -r "${1%%/}.zip" "$1" ; }
|
539
|
+
|
540
|
+
# Make your directories and files access rights sane.
|
541
|
+
function sanitize() { chmod -R u=rwX,g=rX,o= "$@" ;}
|
542
|
+
|
543
|
+
#-------------------------------------------------------------
|
544
|
+
# Process/system related functions:
|
545
|
+
#-------------------------------------------------------------
|
546
|
+
|
547
|
+
|
548
|
+
function my_ps() { ps $@ -u $USER -o pid,%cpu,%mem,bsdtime,command ; }
|
549
|
+
function pp() { my_ps f | awk '!/awk/ && $0~var' var=${1:-".*"} ; }
|
550
|
+
|
551
|
+
|
552
|
+
function killps() # kill by process name
|
553
|
+
{
|
554
|
+
local pid pname sig="-TERM" # default signal
|
555
|
+
if [ "$#" -lt 1 ] || [ "$#" -gt 2 ]; then
|
556
|
+
echo "Usage: killps [-SIGNAL] pattern"
|
557
|
+
return;
|
558
|
+
fi
|
559
|
+
if [ $# = 2 ]; then sig=$1 ; fi
|
560
|
+
for pid in $(my_ps| awk '!/awk/ && $0~pat { print $1 }' pat=${!#} )
|
561
|
+
do
|
562
|
+
pname=$(my_ps | awk '$1~var { print $5 }' var=$pid )
|
563
|
+
if ask "Kill process $pid <$pname> with signal $sig?"
|
564
|
+
then kill $sig $pid
|
565
|
+
fi
|
566
|
+
done
|
567
|
+
}
|
568
|
+
|
569
|
+
function mydf() # Pretty-print of 'df' output.
|
570
|
+
{ # Inspired by 'dfc' utility.
|
571
|
+
for fs ; do
|
572
|
+
|
573
|
+
if [ ! -d $fs ]
|
574
|
+
then
|
575
|
+
echo -e $fs" :No such file or directory" ; continue
|
576
|
+
fi
|
577
|
+
|
578
|
+
local info=( $(command df -P $fs | awk 'END{ print $2,$3,$5 }') )
|
579
|
+
local free=( $(command df -Pkh $fs | awk 'END{ print $4 }') )
|
580
|
+
local nbstars=$(( 20 * ${info[1]} / ${info[0]} ))
|
581
|
+
local out="["
|
582
|
+
for ((j=0;j<20;j++)); do
|
583
|
+
if [ ${j} -lt ${nbstars} ]; then
|
584
|
+
out=$out"*"
|
585
|
+
else
|
586
|
+
out=$out"-"
|
587
|
+
fi
|
588
|
+
done
|
589
|
+
out=${info[2]}" "$out"] ("$free" free on "$fs")"
|
590
|
+
echo -e $out
|
591
|
+
done
|
592
|
+
}
|
593
|
+
|
594
|
+
|
595
|
+
function my_ip() # Get IP adress on ethernet.
|
596
|
+
{
|
597
|
+
MY_IP=$(/sbin/ifconfig eth0 | awk '/inet/ { print $2 } ' |
|
598
|
+
sed -e s/addr://)
|
599
|
+
echo ${MY_IP:-"Not connected"}
|
600
|
+
}
|
601
|
+
|
602
|
+
function ii() # Get current host related info.
|
603
|
+
{
|
604
|
+
echo -e "\nYou are logged on ${BRed}$HOST"
|
605
|
+
echo -e "\n${BRed}Additionnal information:$NC " ; uname -a
|
606
|
+
echo -e "\n${BRed}Users logged on:$NC " ; w -hs |
|
607
|
+
cut -d " " -f1 | sort | uniq
|
608
|
+
echo -e "\n${BRed}Current date :$NC " ; date
|
609
|
+
echo -e "\n${BRed}Machine stats :$NC " ; uptime
|
610
|
+
echo -e "\n${BRed}Memory stats :$NC " ; free
|
611
|
+
echo -e "\n${BRed}Diskspace :$NC " ; mydf / $HOME
|
612
|
+
echo -e "\n${BRed}Local IP Address :$NC" ; my_ip
|
613
|
+
echo -e "\n${BRed}Open connections :$NC "; netstat -pan --inet;
|
614
|
+
echo
|
615
|
+
}
|
616
|
+
|
617
|
+
#-------------------------------------------------------------
|
618
|
+
# Misc utilities:
|
619
|
+
#-------------------------------------------------------------
|
620
|
+
|
621
|
+
function repeat() # Repeat n times command.
|
622
|
+
{
|
623
|
+
local i max
|
624
|
+
max=$1; shift;
|
625
|
+
for ((i=1; i <= max ; i++)); do # --> C-like syntax
|
626
|
+
eval "$@";
|
627
|
+
done
|
628
|
+
}
|
629
|
+
|
630
|
+
|
631
|
+
function ask() # See 'killps' for example of use.
|
632
|
+
{
|
633
|
+
echo -n "$@" '[y/n] ' ; read ans
|
634
|
+
case "$ans" in
|
635
|
+
y*|Y*) return 0 ;;
|
636
|
+
*) return 1 ;;
|
637
|
+
esac
|
638
|
+
}
|
639
|
+
|
640
|
+
function corename() # Get name of app that created a corefile.
|
641
|
+
{
|
642
|
+
for file ; do
|
643
|
+
echo -n $file : ; gdb --core=$file --batch | head -1
|
644
|
+
done
|
645
|
+
}
|
646
|
+
|
647
|
+
#-------------------------------------------------------------
|
648
|
+
# Export Environment Variables
|
649
|
+
#-------------------------------------------------------------
|
650
|
+
|
651
|
+
export PATH=$PATH:"/test"
|
652
|
+
export PATH=$PATH:"/duplicate"
|
data/test/test_confinicky.rb
CHANGED
@@ -1,9 +1,21 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
class TestConfinicky < MiniTest::
|
3
|
+
class TestConfinicky < MiniTest::Test
|
4
4
|
|
5
|
-
def
|
6
|
-
|
5
|
+
def setup
|
6
|
+
@shell_file = Confinicky::ShellFile.new(file_path: 'test/sample_bash_file.sh')
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_shell_file_duplicates
|
10
|
+
assert_equal 1, @shell_file.find_duplicates.length
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_exports_without_assignments
|
14
|
+
assert_includes @shell_file.lines, "export DISPLAY\n"
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_detects_exports_with_assignment
|
18
|
+
assert_equal 18, @shell_file.exports.length
|
7
19
|
end
|
8
20
|
|
9
21
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'helper'
|
3
|
+
|
4
|
+
class TestFileWriting < MiniTest::Test
|
5
|
+
|
6
|
+
def setup
|
7
|
+
FileUtils.cp 'test/sample_bash_file.sh', 'test/sample_bash_file.sh.tmp'
|
8
|
+
@shell_file = Confinicky::ShellFile.new(file_path: 'test/sample_bash_file.sh.tmp')
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_clean_file
|
12
|
+
@shell_file.clean!
|
13
|
+
assert_equal 17, @shell_file.exports.length
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_add_var
|
17
|
+
@shell_file.set!("NEW_VAR=12345")
|
18
|
+
assert_equal 19, @shell_file.exports.length
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_remove_var
|
22
|
+
@shell_file.remove!("PATH")
|
23
|
+
assert_equal 16, @shell_file.exports.length
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_add_var_should_not_duplicate
|
27
|
+
@shell_file.set!("NEW_VAR=12345")
|
28
|
+
@shell_file.set!("NEW_VAR=123456")
|
29
|
+
assert_equal 19, @shell_file.exports.length
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_whitespace
|
33
|
+
@shell_file.set!("NEW_STRING=A String")
|
34
|
+
assert_equal 1, @shell_file.exports.delete_if{|i| i[1] != "\'A String\'"}.length
|
35
|
+
end
|
36
|
+
|
37
|
+
def teardown
|
38
|
+
FileUtils.rm 'test/sample_bash_file.sh.tmp'
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: confinicky
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jim Jeffers
|
@@ -108,10 +108,10 @@ dependencies:
|
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0.9'
|
111
|
-
description: A CLI
|
111
|
+
description: A simple CLI to manage environment variables on your local machine. Perform
|
112
|
+
basic CRUD for your environment variables all in the command line.
|
112
113
|
email: jim@sumocreations.com
|
113
114
|
executables:
|
114
|
-
- confinicky
|
115
115
|
- cfy
|
116
116
|
extensions: []
|
117
117
|
extra_rdoc_files:
|
@@ -124,12 +124,9 @@ files:
|
|
124
124
|
- LICENSE.txt
|
125
125
|
- README.rdoc
|
126
126
|
- Rakefile
|
127
|
-
- VERSION
|
128
127
|
- bin/cfy
|
129
|
-
- bin/confinicky
|
130
128
|
- confinicky.gemspec
|
131
129
|
- lib/confinicky.rb
|
132
|
-
- lib/confinicky/boot.rb
|
133
130
|
- lib/confinicky/commands.rb
|
134
131
|
- lib/confinicky/commands/clean.rb
|
135
132
|
- lib/confinicky/commands/duplicates.rb
|
@@ -139,8 +136,11 @@ files:
|
|
139
136
|
- lib/confinicky/commands/use.rb
|
140
137
|
- lib/confinicky/config.rb
|
141
138
|
- lib/confinicky/shell_file.rb
|
139
|
+
- lib/confinicky/version.rb
|
142
140
|
- test/helper.rb
|
141
|
+
- test/sample_bash_file.sh
|
143
142
|
- test/test_confinicky.rb
|
143
|
+
- test/test_file_writing.rb
|
144
144
|
homepage: http://github.com/jimjeffers/confinicky
|
145
145
|
licenses:
|
146
146
|
- MIT
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.1.4
|
data/bin/confinicky
DELETED
data/lib/confinicky/boot.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'commander/import'
|
2
|
-
require 'terminal-table'
|
3
|
-
require 'confinicky'
|
4
|
-
|
5
|
-
HighLine.track_eof = false # Fix for built-in Ruby
|
6
|
-
Signal.trap("INT") {} # Suppress backtrace when exiting command
|
7
|
-
|
8
|
-
program :version, "0.1.3"
|
9
|
-
program :description, 'A command-line interface for managing your shell environment variables.'
|
10
|
-
|
11
|
-
program :help, 'Author', 'Jim Jeffers <jim@sumocreations.com>'
|
12
|
-
program :help, 'Website', 'https://github.com/jimjeffers'
|
13
|
-
program :help_formatter, :compact
|
14
|
-
|
15
|
-
default_command :help
|
16
|
-
|
17
|
-
require 'confinicky/commands'
|