Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
  • 10 commits
  • 11 files changed
  • 0 commit comments
  • 3 contributors
View
3  DocRoot/index.php
@@ -35,11 +35,8 @@
} else {
// Setup the OOP autoloader
include( 'PHP/Includes/eGlooAutoload.php' );
-
-
}
-
// Check for Memcache
if (!extension_loaded('memcache') && !extension_loaded('memcached')) {
echo 'Memcache support not detected. Please install Memcache or Memcached for PHP.';
View
4 PHP/Classes/System/Messaging/Deprecated/eGlooAlert.php
@@ -89,4 +89,6 @@ public static function sendSMSAlert() {
}
-deprecate( __FILE__, '\eGloo\Messaging\Alert' );
+if ( !defined('STDIN') && class_exists('\eGloo\Messaging\Alert', false) ) {
+ deprecate( __FILE__, '\eGloo\Messaging\Alert' );
+}
View
42 Scripts/clean_template.rb
@@ -0,0 +1,42 @@
+#!/usr/bin/env ruby
+
+# Removes property messages to object receiver - ie, converts to associative array
+
+# REQUIRES
+
+require 'erb'
+require 'fileutils'
+
+# GO
+
+# raise exceptions if an argument does not exist, or if it is not valid file
+raise 'You must pass a valid file argument' if ARGV.empty?
+raise 'File argument is invalid' unless File.file? (file = ARGV[0])
+raise 'You\'ve already cleaned this template or remove backup' if File.file? ("#{File.dirname(file)}/#{File.basename(file)}.backup")
+
+
+
+
+# open file and look for php instance patterns
+content = nil
+
+File.open(file) do | file |
+ content = file.read.gsub(/\$([a-zA-Z_0-9]+)\-\>([a-zA-Z_0-9]+)(\(.*?\))?(\-\>([A-Za-z0-9_]+))?/) do | match |
+ object, key, multi = $1, $2, $5
+
+ replace = "$#{object}.#{key.sub /^get/, ''}"
+ replace += ".#{multi}" unless multi.nil?
+
+
+ replace
+ end
+end
+
+
+# make a copy/backup of file
+path = File.dirname file
+
+FileUtils.copy file, "#{path}/#{File.basename(file)}.backup"
+
+# overwrite target
+IO.write file, content
View
6 Scripts/dump_log
@@ -1,6 +0,0 @@
-# 0x00000: 54 72 79 69 6e 67 20 6c 6f 63 61 6c 68 6f 73 74 Trying localhost
-# 0x00010: 2e 2e 2e 0a ....
-
-# 0x00000: 43 6f 6e 6e 65 63 74 65 64 20 74 6f 20 6c 6f 63 Connected to loc
-# 0x00010: 61 6c 68 6f 73 74 2e 0a alhost..
-
View
172 Scripts/egloo.osx
@@ -0,0 +1,172 @@
+#! /usr/bin/env php -q
+<?php
+namespace eGloo;
+
+use \eGloo\Combine\Help as Help;
+
+/**
+ * eGloo Framework Control Script
+ *
+ * This file contains the control script for the eGloo framework
+ *
+ * Copyright 2011 eGloo, LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * @author George Cooper
+ * @copyright 2011 eGloo, LLC
+ * @license http://www.apache.org/licenses/LICENSE-2.0
+ * @package Scripts
+ * @version 1.0
+ */
+
+// Check for the minimum PHP version to run the framework
+if ( version_compare(PHP_VERSION, '5.3.0', '<') ) {
+ echo 'You are using PHP version ' . PHP_VERSION . '. ' .
+ 'eGloo requires PHP version 5.3.0 or higher.';
+ exit;
+}
+
+// Check for Memcache
+if ( !extension_loaded('memcache') && !extension_loaded('memcached') ) {
+ echo 'Memcache support not detected. Please install Memcache or Memcached for PHP.';
+ exit;
+}
+
+// Let's grab the arguments that are directed at the script execution (not command/subcommand)
+// This would be anything starting with a dash (-) or double dash (--) before the first argument
+// which does not contain one (which should be either local, or some command such as data or forms)
+$egloo_script_arguments = array();
+$command_found = false;
+
+while ( !$command_found && count($argv) > 1 ) {
+ // Why is this in a while loop? Because slicing and splicing arrays resets array pointers.
+ foreach( $argv as $argument_key => $argument_value ) {
+ if ( $argument_key === 0 ) continue;
+
+ $matches = array();
+ preg_match('/^-{1,2}[^ -]+.*$/', $argument_value, $matches);
+
+ if ( !empty($matches) && isset($matches[0]) ) {
+ $egloo_script_arguments[] = $argument_value;
+
+ $array2splice = $argv;
+ $array2slice = $argv;
+
+ array_splice( $array2splice, $argument_key );
+ $array2slice = array_slice($array2slice, $argument_key + 1);
+
+ $argv = array_merge($array2splice, $array2slice);
+ break;
+ }
+
+ $matches = array();
+ preg_match('/^[^-]+.*$/', $argument_value, $matches);
+
+ if ( !empty($matches) && isset($matches[0]) ) {
+ $command_found = true;
+ break;
+ }
+ }
+}
+
+$path_set = false;
+
+// Setup the OOP autoloader
+if ( isset($argv[1]) && $argv[1] === 'local' ) {
+ $argv = array_merge( array($argv[0]), array_slice($argv, 2) );
+
+ $local_path = './PHP/Includes/eGlooCLIAutoload.php';
+
+ if ( file_exists($local_path) && is_file($local_path) && is_readable($local_path) ) {
+ $path_set = true;
+ } else {
+ echo 'Provided path "' . $local_path . '" is not a valid eGloo Framework path. Ignoring...' . "\n";
+ }
+}
+
+if ( !$path_set ) {
+ foreach( $egloo_script_arguments as $argument_key => $argument_value ) {
+ $matches = array();
+ preg_match('/^--egloo-include-path=([a-zA-Z0-9\/_.: -]+)$/', $argument_value, $matches);
+
+ if ( !empty($matches) && isset($matches[1]) ) {
+ $full_path = $matches[1] . '/PHP/Includes/eGlooCLIAutoload.php';
+
+ if ( file_exists($full_path) && is_file($full_path) && is_readable($full_path) ) {
+ set_include_path( $matches[1] . ':' . get_include_path() );
+ $path_set = true;
+ } else {
+ echo 'Provided path "' . $matches[1] . '" is not a valid eGloo Framework path. Ignoring...' . "\n";
+ }
+
+ break;
+ }
+ }
+}
+
+if ( !$path_set && isset( $_SERVER['EGLOO_INCLUDE_PATH'] ) ) {
+ $full_path = $_SERVER['EGLOO_INCLUDE_PATH'] . '/PHP/Includes/eGlooCLIAutoload.php';
+
+ if ( file_exists($full_path) && is_file($full_path) && is_readable($full_path) ) {
+ set_include_path( $_SERVER['EGLOO_INCLUDE_PATH'] . ':' . get_include_path() );
+ $path_set = true;
+ } else {
+ echo 'EGLOO_INCLUDE_PATH value of "' . $_SERVER['EGLOO_INCLUDE_PATH'] . '" is not a valid eGloo Framework path. Ignoring...' . "\n";
+ }
+}
+
+if ( !$path_set ) {
+ $supported_operating_systems = array( 'Mac OS X' => array('Darwin'), 'Ubuntu' => array('Linux') );
+
+ if ( in_array( PHP_OS, $supported_operating_systems['Mac OS X'] ) ) {
+ set_include_path( '/Library/Frameworks/eGloo.framework' . ':' . get_include_path() );
+ $path_set = true;
+ } else if ( in_array( PHP_OS, $supported_operating_systems['Ubuntu'] ) ) {
+ set_include_path( '/usr/lib/eglooframework' . ':' . get_include_path() );
+ $path_set = true;
+ } else {
+ echo 'eGloo CLI OS does not support this operating system. Looking for eGloo Framework in Linux default...' . "\n";
+ set_include_path( '/usr/lib/eglooframework' . ':' . get_include_path() );
+ $path_set = true;
+ }
+}
+
+// We have an include path, so let's attempt to include
+if ( $path_set ) {
+ include( 'PHP/Includes/eGlooCLIAutoload.php' );
+}
+
+// Let's make sure we loaded something here
+if ( !class_exists('\eGloo\CLI') ) {
+ echo 'eGloo Framework not found in expected location.' . "\n\n";
+ echo 'Please provide a valid include path one of two ways:' . "\n";
+ echo '(1) egloo --egloo-include-path=/path/to/eglooframework OR' . "\n";
+ echo '(2) export EGLOO_INCLUDE_PATH=/path/to/eglooframework' . "\n\n";
+ exit;
+}
+
+$arguments = $argv;
+
+CLI::setScriptArguments( $egloo_script_arguments );
+
+if ( isset($arguments[1]) && !is_numeric($arguments[1]) ) {
+ $script_name = array_shift( $arguments );
+ $command = strtolower( array_shift( $arguments ) );
+
+ CLI::execute( $command, $arguments );
+} else {
+ echo Help::getHelpString() . "\n";
+}
+
+exit;
View
172 Scripts/egloo.ubuntu
@@ -0,0 +1,172 @@
+#! /usr/bin/php5 -q
+<?php
+namespace eGloo;
+
+use \eGloo\Combine\Help as Help;
+
+/**
+ * eGloo Framework Control Script
+ *
+ * This file contains the control script for the eGloo framework
+ *
+ * Copyright 2011 eGloo, LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * @author George Cooper
+ * @copyright 2011 eGloo, LLC
+ * @license http://www.apache.org/licenses/LICENSE-2.0
+ * @package Scripts
+ * @version 1.0
+ */
+
+// Check for the minimum PHP version to run the framework
+if ( version_compare(PHP_VERSION, '5.3.0', '<') ) {
+ echo 'You are using PHP version ' . PHP_VERSION . '. ' .
+ 'eGloo requires PHP version 5.3.0 or higher.';
+ exit;
+}
+
+// Check for Memcache
+if ( !extension_loaded('memcache') && !extension_loaded('memcached') ) {
+ echo 'Memcache support not detected. Please install Memcache or Memcached for PHP.';
+ exit;
+}
+
+// Let's grab the arguments that are directed at the script execution (not command/subcommand)
+// This would be anything starting with a dash (-) or double dash (--) before the first argument
+// which does not contain one (which should be either local, or some command such as data or forms)
+$egloo_script_arguments = array();
+$command_found = false;
+
+while ( !$command_found && count($argv) > 1 ) {
+ // Why is this in a while loop? Because slicing and splicing arrays resets array pointers.
+ foreach( $argv as $argument_key => $argument_value ) {
+ if ( $argument_key === 0 ) continue;
+
+ $matches = array();
+ preg_match('/^-{1,2}[^ -]+.*$/', $argument_value, $matches);
+
+ if ( !empty($matches) && isset($matches[0]) ) {
+ $egloo_script_arguments[] = $argument_value;
+
+ $array2splice = $argv;
+ $array2slice = $argv;
+
+ array_splice( $array2splice, $argument_key );
+ $array2slice = array_slice($array2slice, $argument_key + 1);
+
+ $argv = array_merge($array2splice, $array2slice);
+ break;
+ }
+
+ $matches = array();
+ preg_match('/^[^-]+.*$/', $argument_value, $matches);
+
+ if ( !empty($matches) && isset($matches[0]) ) {
+ $command_found = true;
+ break;
+ }
+ }
+}
+
+$path_set = false;
+
+// Setup the OOP autoloader
+if ( isset($argv[1]) && $argv[1] === 'local' ) {
+ $argv = array_merge( array($argv[0]), array_slice($argv, 2) );
+
+ $local_path = './PHP/Includes/eGlooCLIAutoload.php';
+
+ if ( file_exists($local_path) && is_file($local_path) && is_readable($local_path) ) {
+ $path_set = true;
+ } else {
+ echo 'Provided path "' . $local_path . '" is not a valid eGloo Framework path. Ignoring...' . "\n";
+ }
+}
+
+if ( !$path_set ) {
+ foreach( $egloo_script_arguments as $argument_key => $argument_value ) {
+ $matches = array();
+ preg_match('/^--egloo-include-path=([a-zA-Z0-9\/_.: -]+)$/', $argument_value, $matches);
+
+ if ( !empty($matches) && isset($matches[1]) ) {
+ $full_path = $matches[1] . '/PHP/Includes/eGlooCLIAutoload.php';
+
+ if ( file_exists($full_path) && is_file($full_path) && is_readable($full_path) ) {
+ set_include_path( $matches[1] . ':' . get_include_path() );
+ $path_set = true;
+ } else {
+ echo 'Provided path "' . $matches[1] . '" is not a valid eGloo Framework path. Ignoring...' . "\n";
+ }
+
+ break;
+ }
+ }
+}
+
+if ( !$path_set && isset( $_SERVER['EGLOO_INCLUDE_PATH'] ) ) {
+ $full_path = $_SERVER['EGLOO_INCLUDE_PATH'] . '/PHP/Includes/eGlooCLIAutoload.php';
+
+ if ( file_exists($full_path) && is_file($full_path) && is_readable($full_path) ) {
+ set_include_path( $_SERVER['EGLOO_INCLUDE_PATH'] . ':' . get_include_path() );
+ $path_set = true;
+ } else {
+ echo 'EGLOO_INCLUDE_PATH value of "' . $_SERVER['EGLOO_INCLUDE_PATH'] . '" is not a valid eGloo Framework path. Ignoring...' . "\n";
+ }
+}
+
+if ( !$path_set ) {
+ $supported_operating_systems = array( 'Mac OS X' => array('Darwin'), 'Ubuntu' => array('Linux') );
+
+ if ( in_array( PHP_OS, $supported_operating_systems['Mac OS X'] ) ) {
+ set_include_path( '/Library/Frameworks/eGloo.framework' . ':' . get_include_path() );
+ $path_set = true;
+ } else if ( in_array( PHP_OS, $supported_operating_systems['Ubuntu'] ) ) {
+ set_include_path( '/usr/lib/eglooframework' . ':' . get_include_path() );
+ $path_set = true;
+ } else {
+ echo 'eGloo CLI OS does not support this operating system. Looking for eGloo Framework in Linux default...' . "\n";
+ set_include_path( '/usr/lib/eglooframework' . ':' . get_include_path() );
+ $path_set = true;
+ }
+}
+
+// We have an include path, so let's attempt to include
+if ( $path_set ) {
+ include( 'PHP/Includes/eGlooCLIAutoload.php' );
+}
+
+// Let's make sure we loaded something here
+if ( !class_exists('\eGloo\CLI') ) {
+ echo 'eGloo Framework not found in expected location.' . "\n\n";
+ echo 'Please provide a valid include path one of two ways:' . "\n";
+ echo '(1) egloo --egloo-include-path=/path/to/eglooframework OR' . "\n";
+ echo '(2) export EGLOO_INCLUDE_PATH=/path/to/eglooframework' . "\n\n";
+ exit;
+}
+
+$arguments = $argv;
+
+CLI::setScriptArguments( $egloo_script_arguments );
+
+if ( isset($arguments[1]) && !is_numeric($arguments[1]) ) {
+ $script_name = array_shift( $arguments );
+ $command = strtolower( array_shift( $arguments ) );
+
+ CLI::execute( $command, $arguments );
+} else {
+ echo Help::getHelpString() . "\n";
+}
+
+exit;
View
2  Scripts/output_log
@@ -1,2 +0,0 @@
-Trying localhost...
-Connected to localhost.
View
115 Scripts/remote.rb
@@ -0,0 +1,115 @@
+#!/usr/bin/env ruby
+# This is just a port of rlocate - runs remote commands on server
+
+# REQUIRE
+
+require 'optparse'
+require 'net/ssh'
+
+# CONSTANTS
+
+Space = ' '
+Newline = "\n"
+Remote = '192.168.10.7'
+#Remote = '192.168.93.131'
+#User = 'christian'
+User = 'petflowdeveloper'
+Password = 'fe5180zz'
+Editor = 'zend'
+Mount = '/Volumes/' + Remote
+
+
+
+# CLASSES
+
+# add instance method to fixnum to determine
+# if value is positive
+class Fixnum
+ def positive?
+ self >= 0
+ end
+end
+
+# add instance method to array to determine
+# if index is in correct range
+class Array
+ def in_bounds?(index)
+ index.positive? && index <= (self.size - 1)
+ end
+end
+
+class String
+ def ucfirst
+ self.sub (/^(\w)/) { | s | s.capitalize }
+ end
+end
+
+
+# FUNCTIONS
+
+
+# TESTING
+
+# PRODUCTION
+
+
+
+# check if --remote option has been specified, also
+# provide default values should i not want to go
+# through that shit
+
+options = {
+ remote: true,
+ user: User,
+ password: Password,
+ editor: Editor,
+ mount: Mount
+}
+
+OptionParser.new do |opts|
+ opts.banner = 'Usage: example.rb [options]'
+
+ %w(remote user password mount sudo).each do | word |
+ opts.on "-#{word[0]} [VALUE]", "--#{word}" do | value |
+ options[:"#{word}"] = value || true
+ end
+ end
+end.parse!
+
+
+# set options remote to default if remote has been specified,
+# but without a value - this is redundant and needs to be
+# replaced
+options.each_with_index do | (key, value), index |
+ if options[key] == true
+ unless (const = Object.const_get(key.to_s.ucfirst)).nil?
+ options[key] = const unless Object.const_get(key.to_s.ucfirst).nil?
+ end
+ end
+end
+
+# check for sudo flag, in which case, we want to set user to root
+options[:user] = 'root' if options[:sudo]
+
+# make sure something.. anything has been passed as our main
+# argument to locate
+raise 'You forgot to pass a value cunt' if ARGV.empty?
+
+# we are simply passing parameter values to locate command
+parameters = ARGV.join(Space)
+
+# if doing a remote check, we will to ssh into our remote
+# and perform a locate there
+
+# raise an exception if
+begin
+ Net::SSH.start(options[:remote], options[:user], :password => options[:password]) do | ssh |
+ @results = (ssh.exec! "#{parameters}").split Newline
+ end
+
+rescue => error
+ raise "Problem with connection to #{options[:remote]} with error : #{error}"
+
+end
+
+puts @results
View
95 Scripts/rlocate
@@ -4,10 +4,19 @@
# REQUIRE
+require 'optparse'
+require 'net/ssh'
+
# CONSTANTS
-Space = ' '
-Newline = "\n"
+Space = ' '
+Newline = "\n"
+Remote = '192.168.93.131'
+User = 'christian'
+Password = 'fe5180zz'
+Editor = 'zend'
+Mount = '/Volumes/' + Remote
+
# CLASSES
@@ -28,6 +37,11 @@ class Array
end
end
+class String
+ def ucfirst
+ self.sub (/^(\w)/) { | s | s.capitalize }
+ end
+end
# FUNCTIONS
@@ -37,23 +51,84 @@ end
# PRODUCTION
-# make sure something.. anything has been passed
+
+
+# check if --remote option has been specified, also
+# provide default values should i not want to go
+# through that shit
+
+options = {
+ remote: false,
+ user: User,
+ password: Password,
+ editor: Editor,
+ mount: Mount
+}
+
+OptionParser.new do |opts|
+ opts.banner = 'Usage: example.rb [options]'
+
+ %w(remote user password mount).each do | word |
+ opts.on "-#{word[0]} [VALUE]", "--#{word}" do | value |
+ options[:"#{word}"] = value || true
+ end
+ end
+end.parse!
+
+
+# set options remote to default if remote has been specified,
+# but without a value - this is redundant and needs to be
+# replaced
+options.each_with_index do | (key, value), index |
+ if options[key] == true
+ unless (const = Object.const_get(key.to_s.ucfirst)).nil?
+ options[key] = const unless Object.const_get(key.to_s.ucfirst).nil?
+ end
+ end
+end
+
+# make sure something.. anything has been passed as our main
+# argument to locate
raise 'You forgot to pass a value cunt' if ARGV.empty?
# we are simply passing parameter values to locate command
parameters = ARGV.join(Space)
-results = `locate #{parameters}`.split(Newline)
-unless results.empty?
+# if doing a remote check, we will to ssh into our remote
+# and perform a locate there
- if results.length == 1
- `gedit #{results.pop} &`
+if options[:remote]
+
+ # raise an exception if
+ begin
+ Net::SSH.start(options[:remote], options[:user], :password => options[:password]) do | ssh |
+ @results = (ssh.exec! "locate #{parameters}").split Newline
+ end
+
+ rescue => error
+ raise "Problem with connection to #{options[:remote]} with error : #{error}"
+
+ end
+
+# otherwise we simply call a
+else
+ @results = `locate #{parameters}`.split Newline
+end
+
+
+unless @results.empty?
+
+ if @results.length == 1
+ result = @results.pop
+ result = "#{options[:mount]}/#{result}" unless options[:remote] == false
+
+ `#{options[:editor]} #{result} &`
else
# iterate through result set and display as choosable options
# user
- results.each_with_index do | result, index |
+ @results.each_with_index do | result, index |
puts "#{index} ==> #{result}"
end
@@ -63,7 +138,9 @@ unless results.empty?
# with filepath
if (answer = $stdin.gets.chomp).length > 0
answer = answer.to_i
- `gedit #{results[answer]} &` if results.in_bounds?(answer)
+ @results[answer] = options[:mount] + "/#{@results[answer]}" unless options[:remote] == false
+
+ `#{options[:editor]} #{@results[answer]} &` if @results.in_bounds?(answer)
end
end
end
View
151 Scripts/rlocate.rb
@@ -0,0 +1,151 @@
+#!/usr/bin/env ruby
+# Runs locate command and returns numbered list from which to launch gedit on
+# located files
+# Feature Wish List:
+# Need to cache results for N seconds since remote connection can take some time
+# or keep connection alive in background
+
+# REQUIRE
+
+require 'optparse'
+require 'net/ssh'
+
+# CONSTANTS
+
+Space = ' '
+Newline = "\n"
+Remote = '192.168.10.7'
+#Remote = '192.168.93.131'
+#User = 'christian'
+User = 'petflowdeveloper'
+Password = 'fe5180zz'
+Editor = 'zend'
+Mount = '/Volumes/' + Remote
+
+
+
+# CLASSES
+
+# add instance method to fixnum to determine
+# if value is positive
+class Fixnum
+ def positive?
+ self >= 0
+ end
+end
+
+# add instance method to array to determine
+# if index is in correct range
+class Array
+ def in_bounds?(index)
+ index.positive? && index <= (self.size - 1)
+ end
+end
+
+class String
+ def ucfirst
+ self.sub (/^(\w)/) { | s | s.capitalize }
+ end
+end
+
+
+# FUNCTIONS
+
+
+# TESTING
+
+# PRODUCTION
+
+
+
+# check if --remote option has been specified, also
+# provide default values should i not want to go
+# through that shit
+
+options = {
+ remote: false,
+ user: User,
+ password: Password,
+ editor: Editor,
+ mount: Mount
+}
+
+OptionParser.new do |opts|
+ opts.banner = 'Usage: example.rb [options]'
+
+ %w(remote user password mount).each do | word |
+ opts.on "-#{word[0]} [VALUE]", "--#{word}" do | value |
+ options[:"#{word}"] = value || true
+ end
+ end
+end.parse!
+
+
+# set options remote to default if remote has been specified,
+# but without a value - this is redundant and needs to be
+# replaced
+options.each_with_index do | (key, value), index |
+ if options[key] == true
+ unless (const = Object.const_get(key.to_s.ucfirst)).nil?
+ options[key] = const unless Object.const_get(key.to_s.ucfirst).nil?
+ end
+ end
+end
+
+# make sure something.. anything has been passed as our main
+# argument to locate
+raise 'You forgot to pass a value cunt' if ARGV.empty?
+
+# we are simply passing parameter values to locate command
+parameters = ARGV.join(Space)
+
+# if doing a remote check, we will to ssh into our remote
+# and perform a locate there
+
+if options[:remote]
+
+ # raise an exception if
+ begin
+ Net::SSH.start(options[:remote], options[:user], :password => options[:password]) do | ssh |
+ @results = (ssh.exec! "locate #{parameters}").split Newline
+ end
+
+ rescue => error
+ raise "Problem with connection to #{options[:remote]} with error : #{error}"
+
+ end
+
+# otherwise we simply call a
+else
+ @results = `locate #{parameters}`.split Newline
+end
+
+
+unless @results.empty?
+
+ if @results.length == 1
+ result = @results.pop
+ result = "#{options[:mount]}/#{result}" unless options[:remote] == false
+
+ `#{options[:editor]} #{result} &`
+
+ else
+
+ # iterate through result set and display as choosable options
+ # user
+ @results.each_with_index do | result, index |
+ puts "#{index} ==> #{result}"
+ end
+
+ print "\nchoose from above index: "
+
+ # recieve user input from command line and launch gedit
+ # with filepath
+ if (answer = $stdin.gets.chomp).length > 0
+ answer = answer.to_i
+ @results[answer] = options[:mount] + "/#{@results[answer]}" unless options[:remote] == false
+
+ `#{options[:editor]} #{@results[answer]} &` if @results.in_bounds?(answer)
+ end
+ end
+end
View
155 Scripts/rpass.rb
@@ -0,0 +1,155 @@
+#!/usr/bin/env ruby
+# The point of this script is to run a rlocate, but pass the resulting path
+# to another command - so in essence it works as a pipe; the only difference
+# here is that we add the pipe through at the end, and make sure to account
+# for command at beginning
+
+# REQUIRE
+
+require 'optparse'
+require 'net/ssh'
+
+# CONSTANTS
+
+Space = ' '
+Newline = "\n"
+Remote = '192.168.10.7'
+#Remote = '192.168.93.131'
+#User = 'christian'
+User = 'petflowdeveloper'
+Password = 'fe5180zz'
+Editor = 'zend'
+Mount = '/Volumes/' + Remote
+
+
+
+# CLASSES
+
+# add instance method to fixnum to determine
+# if value is positive
+class Fixnum
+ def positive?
+ self >= 0
+ end
+end
+
+# add instance method to array to determine
+# if index is in correct range
+class Array
+ def in_bounds?(index)
+ index.positive? && index <= (self.size - 1)
+ end
+end
+
+class String
+ def ucfirst
+ self.sub (/^(\w)/) { | s | s.capitalize }
+ end
+end
+
+
+# FUNCTIONS
+
+
+# TESTING
+
+# PRODUCTION
+
+
+
+# check if --remote option has been specified, also
+# provide default values should i not want to go
+# through that shit
+
+options = {
+ remote: false,
+ command: false,
+ user: User,
+ password: Password,
+ editor: Editor,
+ mount: Mount
+}
+
+OptionParser.new do |opts|
+ opts.banner = 'Usage: example.rb [options]'
+
+ %w(remote user password mount command).each do | word |
+ opts.on "-#{word[0]} [VALUE]", "--#{word}" do | value |
+ options[:"#{word}"] = value || true
+ end
+ end
+end.parse!
+
+
+raise 'You must specify a command via --command or -c flag' unless options[:command]
+
+
+# set options remote to default if remote has been specified,
+# but without a value - this is redundant and needs to be
+# replaced
+options.each_with_index do | (key, value), index |
+ if options[key] == true
+ unless (const = Object.const_get(key.to_s.ucfirst)).nil?
+ options[key] = const unless Object.const_get(key.to_s.ucfirst).nil?
+ end
+ end
+end
+
+# make sure something.. anything has been passed as our main
+# argument to locate
+raise 'You forgot to pass a value cunt' if ARGV.empty?
+
+# we are simply passing parameter values to locate command
+parameters = ARGV.join(Space)
+
+# if doing a remote check, we will to ssh into our remote
+# and perform a locate there
+
+if options[:remote]
+
+ # raise an exception if
+ begin
+ Net::SSH.start(options[:remote], options[:user], :password => options[:password]) do | ssh |
+ @results = (ssh.exec! "locate #{parameters}").split Newline
+ end
+
+ rescue => error
+ raise "Problem with connection to #{options[:remote]} with error : #{error}"
+
+ end
+
+# otherwise we simply call a
+else
+ @results = `locate #{parameters}`.split Newline
+end
+
+
+unless @results.empty?
+
+ if @results.length == 1
+ result = @results.pop
+ result = "#{options[:mount]}/#{result}" unless options[:remote] == false
+
+ else
+
+ # iterate through result set and display as choosable options
+ # user
+ @results.each_with_index do | result, index |
+ puts "#{index} ==> #{result}"
+ end
+
+ print "\nchoose from above index: "
+
+ # recieve user input from command line and launch gedit
+ # with filepath
+ if (answer = $stdin.gets.chomp).length > 0
+ answer = answer.to_i
+ @results[answer] = options[:mount] + "/#{@results[answer]}" unless options[:remote] == false
+
+ result = @results[answer] if @results.in_bounds?(answer)
+ end
+ end
+
+ # now push result to command
+ puts `#{options[:command]} #{result}`
+end

No commit comments for this range

Something went wrong with that request. Please try again.