diff --git a/bin/findroot b/bin/findroot new file mode 100755 index 0000000..a3c4a5a --- /dev/null +++ b/bin/findroot @@ -0,0 +1,15 @@ +#! /usr/bin/env python3 + +import sys +from mbutils import find_root + +try: + print(find_root(*sys.argv[1:])) + sys.exit(0) +except IOError: + print("File not found in any directory", file=sys.stderr) + sys.exit(1) +except TypeError: + print("No filename specified", file=sys.stderr) + sys.exit(2) + diff --git a/lib/python/mbutils.py b/lib/python/mbutils.py index 7ffce44..afee9ec 100644 --- a/lib/python/mbutils.py +++ b/lib/python/mbutils.py @@ -6,6 +6,11 @@ from collections import OrderedDict from functools import cmp_to_key def find_in_parent(filename, starting_dir=None): + '''Look up the directory tree until you find a file.''' + root = find_root(filename, starting_dir) + return path.join(root, filename) + +def find_root(filename, starting_dir=None): '''Look up the directory tree until you find a file.''' if starting_dir is None: starting_dir = os.getcwd() @@ -13,11 +18,11 @@ def find_in_parent(filename, starting_dir=None): candidate_file = path.join(starting_dir, filename) if (path.isfile(candidate_file)): - return candidate_file + return starting_dir elif starting_dir == '/': raise IOError('File not found in any directory') else: - return find_in_parent(filename, path.dirname(starting_dir)) + return find_root(filename, path.dirname(starting_dir)) def _parse_composer_manifest(path): '''Parse composer.json into dict''' diff --git a/zsh/zshrc.symlink b/zsh/zshrc.symlink index 28de969..009ff4b 100644 --- a/zsh/zshrc.symlink +++ b/zsh/zshrc.symlink @@ -136,4 +136,57 @@ setopt extended_history # to do things correctly and see if it's slow. setopt hist_lex_words +# Liquid Prompt! source "$HOME/.zsh/liquidprompt/liquidprompt" + +# Create MySQL Docker container +function provision_mysql { + mkdir -p "$HOME/Data/5.6/data" && docker run -d\ + --name="mysql-5.6" \ + -e "MYSQL_ROOT_PASSWORD=root" \ + -p 33306:3306 \ + -v "$HOME/Data/5.6/data:/tmp/data" \ + -v "/var/lib/mysql" \ + "mysql:5.6" +} + +# Access MySQL Docker container +alias mysql='docker exec -it "mysql-5.6" mysql -uroot -proot' + +# Install Magento 2 +function install_magento { + local host="$1" + local db_name="$2" + + n98-magerun2 setup:install \ + --admin-firstname="Max" \ + --admin-lastname="Bucknell" \ + --admin-email="me@maxbucknell.com" \ + --admin-user="max.bucknell" \ + --admin-password="password123" \ + --base-url="http://$host:15013/index.php/" \ + --backend-frontname="admin" \ + --db-host="127.0.0.1:33306" \ + --db-name="$db_name" \ + --db-user="root" \ + --db-password="root" \ + --language="en_US" \ + --currency="EUR" \ + --timezone="UTC" \ + --use-rewrites="1" \ + --use-secure="0" \ + --use-secure-admin="0" \ + --admin-use-security-key="0" \ + --session-save="files" +} + +# Find root of Magetno 2 installation +alias find_magento_root='findroot "app/etc/config.php"' + +# Start M2 server +function serve_m2 { + local root="$(find_magento_root)" + pushd "$root/pub" + php -S "0.0.0.0:15013" "../phpserver/router.php" "../pub" + popd +}