Created
October 27, 2017 11:03
-
-
Save Grummfy/b059a8493e175d77ae73cf1769ad0064 to your computer and use it in GitHub Desktop.
2017-10-27_forumphp-git-vers-l-infini-et-au-delà
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# see /usr/share/bash-completion/completions/git | |
_git_auteur () | |
{ | |
case "$cur" in | |
-*) | |
__gitcomp "-h -v" | |
return | |
;; | |
*) | |
__gitcomp "perso pro" | |
return | |
;; | |
esac | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source bash-completion | |
PATH=$PATH:$PWD | |
git auteur [TAB] | |
git auteur -[TAB] | |
git auteur p[TAB] | |
git auteur | |
amélioration possible | |
* utiliser un fichier de configuration ou la configuration de git (portabilité) | |
* sécurisé les retours des appels | |
* valider que l'on est dans un dossier git | |
* ... | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/php | |
<?php | |
function help() | |
{ | |
echo 'you need help, too bad!', PHP_EOL; | |
} | |
function switchConfig(string $user, string $email, string $sign) | |
{ | |
passthru('git config --local user.name "' . $user . '"'); | |
passthru('git config --local user.email "' . $email . '"'); | |
passthru('git config --local user.signingkey "' . $sign . '"'); | |
} | |
function askProfileType() | |
{ | |
readline_completion_function(function() | |
{ | |
return ['pro', 'perso']; | |
}); | |
$reponse = readline('Quel profil local git appliqué? : '); | |
switchProfileType(trim($reponse)); | |
} | |
function switchProfileType(string $profileType) | |
{ | |
switch ($profileType) | |
{ | |
case 'perso': | |
echo 'On applique une configuration *perso*', PHP_EOL; | |
switchConfig('Grummfy', 'me@grummfy.be', 'AAAEEEVV'); | |
break; | |
case 'pro': | |
echo 'On applique une configuration *pro*', PHP_EOL; | |
switchConfig('jvb', 'jvb@company.tld', 'VVAAAEEE'); | |
break; | |
case '': | |
askProfileType(); | |
break; | |
case '-v': | |
echo 'Version 1.2.3', PHP_EOL; | |
break; | |
# case '-h': | |
# case '--help': | |
default: | |
help(); | |
break; | |
} | |
} | |
$profileType = array_key_exists(1, $argv) ? $argv[1] : ''; | |
switchProfileType($profileType); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment