University of Oregon

Bash – Add drupal site name to PS1

I updated my bash prompt (PS1) the other day. Now it displays what site I’m in.
I recently posted my former change: An improved PS1 for Git in Bash.
Now I added an extra bit of code that inserts the current ‘site’.
It looks like this:

vid@server:(prod.mydomain.com) currentdir (origin [master])$ 

(more…)

An improved PS1 for Git in Bash

Last year I updated my bash prompt (PS1) to include the active git branch name.
A few months ago I added to the the active repository name.
So here’s an example of my PS1 when I’m in a git tracked directory on the master branch:

vid@server mydirectory (origin [master])$ 

And here it is when I have other remote repositories for the same project (bronze and heuristics);

vid@server mydirectory (bronze | heuristics | origin [master])$ 

And now once more when I’m on a branch (devel) that doesn’t exist on the available remotes:

vid@server mydirectory (bronze | origin [devel])$ 

That’s achieved with these functions: parse_git_branch and show-git-current-remotes-short.
(more…)

Bind commands in .bash files don't play nice with Dreamhost logins

Recently I posted a link to some code highlights: Auto populate from History via up and down arrow keys.
I’ve been using that code for several years in a number of bash terminals; on my Mac, several RedHat 5 & 6 Linux servers and on a few hosting accounts on Dreamhost.

One small piece of that code no longer plays nice with Dreamhost.
Something changed on the server-side that is in conflict with 1 or 2 lines of code so that users can not SFTP into the server with a valid user name and password. Authentication with ssh keys however continues to work.

Here’s the offending code found in my .bashrc file:
bind ‘”e[A”‘:history-search-backward
bind ‘”e[B”‘:history-search-forward

(more…)

Auto populate from History via up and down arrow keys

I posted a highlight of some bash code that Jason H shared last year in my git_bash_files repo on bitbucket. Auto_populate_from_History_via_up_and_down_arrow_keys

bash function – cddrush

This is a quick function that reduces the keystrokes for using ‘drush dd’ in a cd command like so:

cd `drush dd @my.site.alias:%site`

Which is great but this is simpler

cddrush my.site.alias

Oh, that’s nice!
(more…)

bash function – git-patch()

We’ve been trying to review more Drupal 8 patches on Drupal.org with this workflow:

$ cd #to your local Drupal 8 Dir.
$ curl https://drupal.org/files/patch_url... | git apply --stat
$ curl https://drupal.org/files/patch_url... | git apply --check
$ curl https://drupal.org/files/patch_url... | git apply
# If no errors occur you can use
$git am --signoff < fix_empty_poster.patch

I found that be cumbersome so I created a bash function to simplify this.
Usage example: $ git-patch stat URL.patch
That triggers a

  • wget to retrieve the file,
  • runs $ git apply –stat
  • and prompts you for the next step.

In addition if you call the function with no vars it returns a simple usage message.
It works great, it’s more efficient and I don’t have to refer back to the patching best-practices if I forget*.
(more…)

bash function – ssh-copy-id for mac

The bash function: ssh-copy-id is a linux script that enables you to copy your public ssh key to a remote server for authenticated but password-less ssh sessions. Apparently it can be installed on a mac but I had no luck, so following the logic found in a comment: https://discussions.apple.com/message/13166537#13166537
I created a mac version of the function to put in .bashrc file.

function ssh-copy-id-mac() { #mac version of ssh-copy-id: cat ~/.ssh/id_rsa.pub | ssh admin@mydomain.net “umask 077; mkdir -p .ssh ; cat >> .ssh/authorized_keys”
#!/bin/sh
#from https://discussions.apple.com/message/13166537#13166537
if [[ ! -n “$1” ]] ; then
echo 1>&2 Usage: $0 user@server
else
cat ~/.ssh/id_rsa.pub | ssh $1 “umask 077; mkdir -p .ssh ; cat >> .ssh/authorized_keys”
fi
}