Skip to content

Commit

Permalink
Add bash prompt customization to init command.
Browse files Browse the repository at this point in the history
  • Loading branch information
weitzman committed Nov 19, 2015
1 parent f2bafe1 commit 1c7bd8e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
19 changes: 15 additions & 4 deletions commands/core/init.drush.inc
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ function drush_init_core_init() {
$drush_config_dir = $home . "/.drush";
$drush_config_file = $drush_config_dir . "/drushrc.php";
$drush_bashrc = $drush_config_dir . "/drush.bashrc";
$drush_prompt = $drush_config_dir . "/drush.prompt.sh";
$examples_dir = DRUSH_BASE_PATH . "/examples";
$example_configuration = $examples_dir . "/example.drushrc.php";
$example_bashrc = $examples_dir . "/example.bashrc";
$example_prompt = $examples_dir . "/example.prompt.sh";
$bashrc_additions = array();

// Create a ~/.drush directory if it does not yet exist
Expand All @@ -52,16 +54,25 @@ function drush_init_core_init() {
// example Drush configuration file here
if (!is_file($drush_config_file)) {
@copy($example_configuration, $drush_config_file);
drush_log(dt("Copied example Drush configuration file to !path", array('!path' => $drush_config_file)), 'ok');
drush_log(dt("Copied example Drush configuration file to !path.", array('!path' => $drush_config_file)), 'ok');
}

// If there is no ~/.drush/drush.bashrc file, then copy
// the example bashrc file here
if (!is_file($drush_bashrc)) {
@copy($example_bashrc, $drush_bashrc);
$pattern = basename($drush_bashrc);
$bashrc_additions["%$pattern%"] = "# Include Drush bash customizations\n. $drush_bashrc\n\n";
drush_log(dt("Copied example Drush bash configuration file to !path", array('!path' => $drush_bashrc)), 'ok');
$bashrc_additions["%$pattern%"] = "# Include Drush bash customizations.\n. $drush_bashrc\n\n";
drush_log(dt("Copied example Drush bash configuration file to !path.", array('!path' => $drush_bashrc)), 'ok');
}

// If there is no ~/.drush/drush.prompt.sh file, then copy
// the example prompt.sh file here
if (!is_file($drush_prompt)) {
@copy($example_prompt, $drush_prompt);
$pattern = basename($drush_prompt);
$bashrc_additions["%$pattern%"] = "# Include Drush prompt customizations.\n. $drush_prompt\n\n";
drush_log(dt("Copied example Drush prompt file to !path.", array('!path' => $drush_prompt)), 'ok');
}

// Decide whether we want to add our Bash commands to
Expand All @@ -75,7 +86,7 @@ function drush_init_core_init() {
$drush_path = drush_find_path_to_drush($home);
$drush_path = preg_replace("%^" . preg_quote($home) . "/%", '$HOME/', $drush_path);

$bashrc_additions["%$drush_path%"] = "# Path to Drush, added by 'drush init'\nexport \$PATH=\"\$PATH:$drush_path\"\n\n";
$bashrc_additions["%$drush_path%"] = "# Path to Drush, added by 'drush init'.\nexport \$PATH=\"\$PATH:$drush_path\"\n\n";
}

// Modify the user's bashrc file, adding our customizations.
Expand Down
7 changes: 0 additions & 7 deletions examples/example.bashrc
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,6 @@ d="$(dirname "$d")"
# If we have found drush.complete.sh, then source it.
if [ -f "$d/drush.complete.sh" ] ; then
. "$d/drush.complete.sh"

# Uncomment these 3 lines to for a prompt that shows Git and Drush status.
# Example: msonnabaum@hostname ~/repos/drush (master)[@sitename]$
# if [ "\$(type -t __git_ps1)" ] && [ "\$(type -t __drush_ps1)" ]; then
# PS1='\u@\h \w$(__git_ps1 " (%s)")$(__drush_ps1 "[%s]")\$ '
# fi

fi

# We extend the cd command to allow convenient
Expand Down
11 changes: 5 additions & 6 deletions examples/example.prompt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#
# Example - rename this to .drush_prompt, and in your ~/.bash_profile add:
#
# if [ -f ~/.drush_prompt ] ; then
# . ~/.drush_prompt
# if [ -f ~/.drush/drush.prompt.sh ] ; then
# . ~/.drush/drush.prompt.sh
# fi
#
# Features:
Expand All @@ -20,13 +20,12 @@ if [ "\$(type -t __git_ps1)" ] && [ "\$(type -t __drush_ps1)" ]; then

# Git offers various prompt customization options as well as seen in
# https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh.
# Uncomment any or all of the following lines to enable the corresponding
# features:
# Adjust the following lines to enable the corresponding features:
#
# GIT_PS1_SHOWDIRTYSTATE=true
GIT_PS1_SHOWDIRTYSTATE=true
GIT_PS1_SHOWUPSTREAM=auto
# GIT_PS1_SHOWSTASHSTATE=true
# GIT_PS1_SHOWUNTRACKEDFILES=true
# GIT_PS1_SHOWUPSTREAM=auto
# GIT_PS1_SHOWCOLORHINTS=true

# The following line sets your bash prompt according to this example:
Expand Down

0 comments on commit 1c7bd8e

Please sign in to comment.