-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunctions
More file actions
123 lines (111 loc) · 2.73 KB
/
functions
File metadata and controls
123 lines (111 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/bin/sh
##
# Functions for bash kit.
#
# This file contains various functions for making life on the command line a
# little bit easier.
##
# Change directory using the name of a directory known to Drupal.
#
# This function utilizes drush's drupal-directory command to change directory
# to the returned path. It used pushd instead of cd to collect a history of
# visited directories.
#
# Usage:
# cdd <name>
#
# Examples:
# cdd devel # Change to the devel module directory.
# cdd modules/custom # Change to custom modules directory (e.g.,
# sites/all/modules/custom).
# cdd # Change to the Drupal root directory.
#
function cdd() {
pushd `drush dd $@` > /dev/null
}
##
# Silently keeps a history of all visited directories.
#
# This function remaps cd to instead use pushd to collect a history of visited
# directories.
#
function cd () {
if [[ -z "$1" ]]; then
builtin cd
else
pushd "$@" > /dev/null
fi
}
##
# Step back through the visited directories history.
#
# Thus function provides a quick and easy way to retrace your steps back
# through recently visited directories.
#
function pd () {
popd "$@" > /dev/null
}
##
# Clone a project from git.drupal.org.
#
function dclone () {
git clone "git://git.drupal.org/project/$1.git"
}
##
# Run a makefile for a given target. Should be used internally.
#
function dmake() {
drush make $1 $2
}
##
# Open given module in the default editor.
#
function e () {
$EDITOR `drush dd $@`
}
##
# Add aliases that persist beyond the current session.
#
# By appending aliases to the file specified by the BASH_KIT_ALIASES
# environment variable, new aliases can persist beyond the current session.
# This is helpful because usually aliases defined using the alias command are
# disgarded at the end of the session and in some cases this is not what is
# desired.
#
# Usage:
# aa <name> <command>
#
# Example:
# aa test date # Maps the date command to be callable using test.
#
function aa () {
if [ ! -f $BASH_KIT_ALIASES ]; then
touch $BASH_KIT_ALIASES
fi
if [ $# -lt 2 ]; then
echo "usage: add <alias> <command>"
return
fi
local command=$1
shift 1
alias="alias $command='$@'"
read -p "Add alias: $alias?"
printf "$alias\n" >> $BASH_KIT_ALIASES
if [ $# ]; then
echo "Alias added"
source $BASH_KIT_ALIASES
else
echo "Failed to add alias"
fi
}
function count_changes () {
stdin=$(cat /dev/stdin);
lines=$(echo "$stdin" | wc -l);
changes=$(echo "$stdin" | grep "^[+-][^+-]" | wc -l);
removed=$(echo "$stdin" | grep "^-[^-]" | wc -l);
added=$(echo "$stdin" | grep "^+[^+]" | wc -l);
echo total $lines lines. $changes altered: $removed removed, $added added.
}
function vo () {
v +/$1 $(g $1 -l);
}