From: Nicolas Boisselier Date: Tue, 21 Jul 2015 09:33:24 +0000 (+0100) Subject: mac.sh, libs X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=1c956b1a0cbbd95bdc83565c922a3ee442f06949;p=nb.git mac.sh, libs --- diff --git a/etc/profile.d/darwin.sh b/etc/profile.d/darwin.sh deleted file mode 100644 index ac6fbbfc..00000000 --- a/etc/profile.d/darwin.sh +++ /dev/null @@ -1,21 +0,0 @@ -mac_pbcopy() { - cat $@ | ssh -q $1 -o 'ForwardAgent yes' 'cat|pbcopy' -} -[ -z "$DARWIN" ] && return 0 - -md5sum() { - md5 $@ | sed "s/^MD5 (\(.*\)) = \(.*\)$/\2 \1/" -} - -mac_xmessage() { - osascript -e "tell app \"System Events\" to display dialog \"$@\"" -} - -mac_config() { - echo "Finder path : YES" - defaults write com.apple.finder _FXShowPosixPathInTitle -bool YES - echo "Finder quit : YES" - defaults write com.apple.finder QuitMenuItem -bool YES - echo "Finder show all files : FALSE" - defaults write com.apple.finder AppleShowAllFiles FALSE -} diff --git a/etc/profile.d/mac.sh b/etc/profile.d/mac.sh new file mode 100644 index 00000000..849918bb --- /dev/null +++ b/etc/profile.d/mac.sh @@ -0,0 +1,46 @@ +# See: http://www.infoworld.com/article/2614879/mac-os-x/top-20-os-x-command-line-secrets-for-power-users.html +mac_pbcopy() { + cat $@ | ssh -q $1 -o 'ForwardAgent yes' 'cat|pbcopy' +} +[ -z "$DARWIN" ] && return 0 + +[ -x /opt/local/bin/mysqld_safe5 ] && alias mac_mysqlstart='sudo /opt/local/bin/mysqld_safe5 &' +[ -x /opt/local/bin/mysqladmin5 ] && alias mac_mysqlstop='/opt/local/bin/mysqladmin5 -u _mysql -p shutdown' +[ -x /Applications/iTunes.app/Contents/MacOS/iTunes ] && alias iTunes=/Applications/iTunes.app/Contents/MacOS/iTunes +[ -x /Applications/VLC.app/Contents/MacOS/VLC ] && alias vlc=/Applications/VLC.app/Contents/MacOS/VLC + +alias mac_vlc_playlists='open -a vlc --args /home/nico/Music/*/*.m3u' +alias mac_top_proc="echo 'TOP PROCESSES:'; ps -Aro'%cpu, ucomm, user' | grep root | grep -v ' 0.0 '" +alias mac_sleep='pmset sleepnow' +alias mac_mount_nfs='sudo mount -o resvport -t nfs' +alias mac_automount='sudo automount -v' +alias mac_dns_flush='sudo dscacheutil -flushcache' +alias mac_halt='halt=1 && bash -c "(sleep 3 && halt) &" && logout' + +mac_config() { + declare run r; run=" +echo 'Finder path : YES' +defaults write com.apple.finder _FXShowPosixPathInTitle -bool YES +echo 'Finder quit : YES' +defaults write com.apple.finder QuitMenuItem -bool YES +echo 'Finder show all files : FALSE' +defaults write com.apple.finder AppleShowAllFiles FALSE +" + echo "$run" + read -p "Run (y)?: " r + [ "$r" = "y" ] || return 1 + echo "$run" | sh +} + +mac_user_top_proci() { + echo "TOP PROCESSES:" + ps -Aro'%cpu, ucomm, user' | grep `whoami` | grep -v ' 0.0 ' +} + +md5sum() { + md5 $@ | sed "s/^MD5 (\(.*\)) = \(.*\)$/\2 \1/" +} + +mac_xmessage() { + osascript -e "tell app \"System Events\" to display dialog \"$@\"" +} diff --git a/lib/php/db.php b/lib/php/db.php index f53e35d8..631ed66e 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -88,6 +88,7 @@ class db { */ function query($sql) { + return $this->query2v($sql); return $this->conn->query($sql); } @@ -118,6 +119,10 @@ class db { return $this->conn->quote($v); } + function table($name) { + return new Table($name,array('db'=>$this)); + } + function tables() { if ($this->tables) return $this->tables; diff --git a/lib/php/db/field.php b/lib/php/db/field.php index e8fc03f9..7f947e20 100644 --- a/lib/php/db/field.php +++ b/lib/php/db/field.php @@ -6,6 +6,7 @@ class field { public $type = 'text'; public $default = null; public $key = false; + public $autoinc = false; function __construct($name,$attr=array()) { $this->name = $name; diff --git a/lib/php/db/table.php b/lib/php/db/table.php index 24f9cc59..56c3dbcc 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -1,5 +1,17 @@ tables()); + $Table = $Db->table($name); + print_r($Table->sql()); +} + if (!defined('DB_HTML_EDIT')) define('DB_HTML_EDIT','Edit'); if (!defined('DB_HTML_DELETE')) define('DB_HTML_DELETE','Delete'); if (!defined('DB_HTML_NAV_TOP')) define('DB_HTML_NAV_TOP',''.PHP_EOL); @@ -41,6 +53,25 @@ class table { return $this->fields(); } + /* + * Function db.sql + * + * return the sql to create the table + * + */ + function sql() { + if ($this->db->type == 'sqlite') { + $sql = "SELECT sql FROM sqlite_master WHERE name='$this->name'"; + } elseif ($this->db->type == 'mysql') { + $sql = "SHOW CREATE TABLE `$this->name`"; + } elseif ($this->db->type == 'pgsql') { + $sql = "SELECT show_create_table('$this->name')"; + } else { + err('table.sql(): Unknow db type: '.$this->db->type); + } + return $this->db->query($sql); + } + /* * Function db.fields * @@ -57,7 +88,7 @@ class table { $sql = "PRAGMA table_info('$this->name')"; } elseif ($this->db->type == 'pgsql') { -$sql = "SELECT + $sql = "SELECT a.attname AS name, pg_catalog.format_type(a.atttypid, a.atttypmod) AS type, CASE a.attnotnull WHEN 't' then 1 ELSE 0 END AS notnull,