-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunctions.sh
More file actions
191 lines (151 loc) · 4.94 KB
/
functions.sh
File metadata and controls
191 lines (151 loc) · 4.94 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
function create_ramdisk() {
size=${1:-"4410000"} # Default to 2.1 GB in blocks if size is not provided
ramdisk_info_file="/tmp/ramdisk_info.txt"
destroy_ramdisk
# Create and attach the ramdisk
ramdisk_dev=$(hdiutil attach -nomount ram://$size | awk '{ print $1 }' | sed 's/ *$//')
echo "ramdisk_dev $ramdisk_dev."
# Partition and format the ramdisk
diskutil partitionDisk $ramdisk_dev 1 GPTFormat APFS 'ramdisk' '100%'
diskutil eraseDisk HFS+ 'ramdisk' $ramdisk_dev
# Write the device identifier to a file
echo "${ramdisk_dev}" > "${ramdisk_info_file}"
echo "Ramdisk mounted at ${ramdisk_dev}"
}
#alias ramdisk="diskutil partitionDisk $(hdiutil attach -nomount ram://2048000) 1 GPTFormat APFS 'ramdisk' '100%'"
function destroy_ramdisk() {
ramdisk_info_file="/tmp/ramdisk_info.txt"
# Read the device identifier from the file
ramdisk_dev=$(cat "${ramdisk_info_file}")
# Unmount and detach the ramdisk
diskutil unmountDisk "${ramdisk_dev}"
hdiutil detach "${ramdisk_dev}"
# Remove the temporary file
rm -f "${ramdisk_info_file}"
echo "Ramdisk unmounted and detached"
}
function find_replace() {
sh $BASH_PROFILE_HOME/rename.sh $1 $2 $3
}
function playsound() {
afplay /System/Library/Sounds/Submarine.aiff
}
function hf() {
history | grep -i $1 | tail -r | less
}
function fn() {
find . -iname "*$1*";
}
function fnin() {
find . -iname "*$1*" -exec grep -il "$2" '{}' +;
}
function gcmc() {
#ticket_name="$(git rev-parse --abbrev-ref HEAD | grep --color=never -oh "\([A-Za-z]*-[0-9]\{,5}\)")"
ticket_name="$(git rev-parse --abbrev-ref HEAD)"
git commit -m "[$ticket_name] $1"
}
function gcm() {
export branchname=$(git symbolic-ref --short HEAD)
git commit -m "$1"
}
function gcmn() {
export branchname=$(git symbolic-ref --short HEAD)
git commit --no-verify -m "$1"
}
function openpr() {
#ticket_name="$(git rev-parse --abbrev-ref HEAD | grep --color=never -oh "\([A-Z]*-[0-9]\{3,4\}\)")"
ticket_name="$(git rev-parse --abbrev-ref HEAD)"
temp_file=$(mktemp)
echo "[$ticket_name] \n\r" > $temp_file
sed -e "s/JIRA-ID/$ticket_name/g" .github/pull_request_template >> $temp_file
vi -c 'set wrap' $temp_file
if [[ $1 ]] then
hub pull-request -F $temp_file -b $1
else
hub pull-request -F $temp_file
fi
}
function link_xcode_data() {
if [ -d "$1" ];
then
rm -rf ~/Library/Developer/Xcode/UserData
ln -s $SCRIPTPATH/Xcode/UserData ~/Library/Developer/Xcode/UserData
fi
}
function asset_resize() {
for f in $(find . -name $1)
do
if ! [[ "@3x" =~ $f ]] then
new_filename="${f%.*}@3x.${f##*.}";
echo "No @3x version to start with, renaming $f to $new_filename";
mv $f $new_filename;
f=$new_filename;
fi
echo "$f -> ${f//@3x/@2x}, ${f//@3x/}";
convert "$f" -resize 66.66666% "${f//@3x/@2x}";
convert "$f" -resize 33.33333% "${f//@3x/}";
done
}
upup(){ DEEP=$1; [ -z "${DEEP}" ] && { DEEP=1; }; for i in $(seq 1 ${DEEP}); do cd ../; done; }
function gcoc() {
MATCHING="$(git branch --list "*$1*")
$(git branch --list --remote "*$1*")";
NUM_MATCHES=`echo $MATCHING | wc -l`;
FINAL_MATCH=''
if [ $NUM_MATCHES -gt 1 ]
then
IFS=$'\n'
BRANCHES=(${=MATCHING})
select branch in "${BRANCHES[@]}"
do
FINAL_MATCH=$branch
break
done
elif [ $NUM_MATCHES -eq 1 ]
then
FINAL_MATCH=$MATCHING
else
echo "No remote or local branch named $1";
fi
FORMATTED_MATCH=`echo $FINAL_MATCH | sed -E "s/[[:space:]]*(origin\/)?//g"`
git checkout $FORMATTED_MATCH
}
function sendpush() {
LAST_EXIT_CODE=$?
CMD=$(fc -ln -1)
# No point in waiting for the command to complete
if [ $LAST_EXIT_CODE -eq 0 ]
then
VERB="failed";
ALERT_NAME="$CMD failed with code $LAST_EXIT_CODE";
else
VERB="succeeded"
ALERT_NAME="$CMD succeeded";
fi
JSON='{"value1":"'"$CMD"'","value2":"'"$VERB"'","value3":"'"$LAST_EXIT_CODE"'"}';
echo $JSON
curl -s -X POST -H "Content-Type: application/json" -d $JSON https://maker.ifttt.com/trigger/long_running_desktop_task/with/key/kMri90fxHSN2xqBR-xQbC12C-iFWbXnXTbBVfVfvLjD > /dev/null
}
function ddd {
echo "Cleaning derived data...";
setopt localoptions rmstarsilent;
rm -rf ~/Library/Developer/Xcode/DerivedData/ 2> /dev/null;
echo "Done."
}
function f_notifyme {
LAST_EXIT_CODE=$?
CMD=$(fc -ln -1)
# No point in waiting for the command to complete
#/Users/akfreas/dotfiles/notifyme.py "$CMD" "$LAST_EXIT_CODE" &
}
function swiftlint_modified() {
git diff --name-only | while read -r file
do
# Check if the file has a .swift extension
if [[ $file == *.swift ]]
then
# Run swiftlint on the file
swiftlint --fix "$file"
fi
done
}