Skip to content

Commit 1458e54

Browse files
committed
Adding fzf and salesforce stuff
1 parent daa657e commit 1458e54

3 files changed

Lines changed: 143 additions & 101 deletions

File tree

.bashrc

Lines changed: 10 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,105 +1195,12 @@ if [ -a "$DOCKER_KEY" ]; then
11951195
export GITHUB_PRIVATE_KEY="$(cat $DOCKER_KEY)"
11961196
fi
11971197

1198-
# Export a function as an entry point to PMD (which we use for Apex linting).
1199-
# This lets us call "apexpmd" from child processes, like npm scripts
1200-
function apexpmd() {
1201-
/usr/local/Cellar/pmd/6.16.0/libexec/bin/run.sh pmd "$@"
1202-
}
1203-
export -f apexpmd
1204-
1205-
# 1 salesforci boi
1198+
# Salesforce stuff
1199+
[ -f ~/.salesforcerc ] && source ~/.salesforcerc
12061200

1207-
# Find the value of any custom labels on a system matching a search pattern
1208-
lbl() {
1209-
if [[ -z "$1" ]] || [[ -z "$2" ]]; then
1210-
echo "Usage: lbl [ORG_ID] [LABEL_REGEX]"
1211-
return 1
1212-
fi
1213-
local result
1214-
result=$(sfdx force:mdapi:listmetadata -m CustomLabel -u "${1}" --json)
1215-
# shellcheck disable=SC2181
1216-
if [ $? -ne 0 ];
1217-
then
1218-
echo "Error!"
1219-
echo "${result}"
1220-
else
1221-
echo "All labels on ${1} matching '${2}' (case insensitive):"
1222-
echo "${result}" | jq -r '.result[] | select(.fullName|test("'"${2}"'"; "i")) | .fullName' | while read -r line ; do
1223-
stmt "${1}" "'${line}: ' + Label.${line}" quiet
1224-
done
1225-
fi
1226-
}
1227-
1228-
# Execute an apex expression against an environment
1229-
exp() {
1230-
if [[ -z "$1" ]] || [[ -z "$2" ]]; then
1231-
echo "Execute an expression, and print the output. Takes the apex expression you pass in and wraps it in a System.debug() call."
1232-
echo "Pass quiet or q as the last paremeter to supress notification messages"
1233-
echo "Usage: exp [ORG_ID] [EXPRESSION_TO_EVALUATE] ['quiet' | 'q']"
1234-
return 1
1235-
fi
1236-
1237-
local apexCommand
1238-
apexCommand='System.debug('"${2}"');'
1239-
if [ "$3" != "quiet" ] && [ "$3" != "q" ]; then
1240-
>&2 echo "${COLOR_BLUE}${BOLD}Executing:${COLOR_RESET}"
1241-
>&2 echo "${COLOR_BLUE}${apexCommand}${COLOR_RESET}"
1242-
>&2 echo
1243-
fi
1244-
1245-
# Example apex output, to see what we're grepping for. Logs for the
1246-
# multline command System.debug('a\nb'):
1247-
# 11:38:56.11 (11521203)|EXECUTION_STARTED
1248-
# 11:38:56.11 (11525424)|CODE_UNIT_STARTED|[EXTERNAL]|execute_anonymous_apex
1249-
# 11:38:56.11 (11944606)|USER_DEBUG|[1]|DEBUG|a
1250-
# b
1251-
# 11:38:56.11 (11980694)|CUMULATIVE_LIMIT_USAGE
1252-
# 11:38:56.11 (11980694)|LIMIT_USAGE_FOR_NS|(default)|
1253-
# We need to find from the start of USER_DEBUG to the next non-debug line.
1254-
# Notice "b" is put on a line by itself, making it tricky to include in output
1255-
1256-
sfdx force:apex:execute -u "${1}" -f /dev/stdin<<<"$apexCommand" | # Execute the expression inside a system.debug(). execute expects a file, so use <<< trick to make it seem like a file
1257-
pcregrep -M 'USER_DEBUG(.|\n)+?([\d]{2}:[\d]{2}:[\d]{2})' | # find debug line, and try to search up to the next apex ouptut line, starting with dd:dd:dd
1258-
sed '$d' | # remove the last line, which is the first non-debug line
1259-
sed 's/.*\|//' # find everything after the last pipe, which will be the debugged output
1260-
}
1261-
1262-
# Execute an apex expression against an environment
1263-
stmt() {
1264-
if [[ -z "$1" ]] || [[ -z "$2" ]]; then
1265-
echo "Execute a statement or list of statements"
1266-
echo "Pass quiet or q as the last paremeter to supress notification messages"
1267-
echo "Usage: stmt [ORG_ID] [STATEMENT_TO_EVALUATE] ['quiet' | 'q']"
1268-
return 1
1269-
fi
1270-
1271-
local apexCommand
1272-
apexCommand=${2}
1273-
if [ "$3" != "quiet" ] && [ "$3" != "q" ]; then
1274-
>&2 echo "${COLOR_BLUE}${BOLD}Executing:${COLOR_RESET}"
1275-
>&2 echo "${COLOR_BLUE}${apexCommand}${COLOR_RESET}"
1276-
>&2 echo
1277-
fi
1278-
1279-
# Example apex output, to see what we're grepping for. Logs for the
1280-
# multline command System.debug('a\nb'):
1281-
# 11:38:56.11 (11521203)|EXECUTION_STARTED
1282-
# 11:38:56.11 (11525424)|CODE_UNIT_STARTED|[EXTERNAL]|execute_anonymous_apex
1283-
# 11:38:56.11 (11944606)|USER_DEBUG|[1]|DEBUG|a
1284-
# b
1285-
# 11:38:56.11 (11980694)|CUMULATIVE_LIMIT_USAGE
1286-
# 11:38:56.11 (11980694)|LIMIT_USAGE_FOR_NS|(default)|
1287-
# We need to find from the start of USER_DEBUG to the next non-debug line.
1288-
# Notice "b" is put on a line by itself, making it tricky to include in output
1289-
1290-
sfdx force:apex:execute -u "${1}" -f /dev/stdin<<<"$apexCommand" # Execute the statement inside a system.debug(). execute expects a file, so use <<< trick to make it seem like a file
1291-
}
1292-
1293-
alias lsorg='open https://grhc.lightning.force.com/lightning/setup/DataManagementCreateTestInstance/home'
1294-
function orgid() {
1295-
exp "$1" 'UserInfo.getOrganizationId()'
1296-
}
1201+
#######
1202+
# FZF #
1203+
#######
12971204

12981205
# Some normal junk
12991206
fzf_opts="--multi --layout=reverse --border"
@@ -1308,5 +1215,9 @@ fzf_opts="${fzf_opts} --preview 'bat --style=numbers --color=always {}'"
13081215
export FZF_DEFAULT_OPTS="$fzf_opts"
13091216
[ -f ~/.fzf.bash ] && source ~/.fzf.bash
13101217

1311-
alias ga="git ls-files -m --exclude-standard | fzf --print0 -m | xargs -0 -t -o git add"
1218+
# Git add selected files with FZF
1219+
alias ga="git ls-files -m --exclude-standard | fzf --print0 -m --preview 'git diff --color=always {}' | xargs -0 -t -o git add"
1220+
1221+
# Git undo changes to selected files with FZF
1222+
alias gx="git ls-files -m --exclude-standard | fzf --print0 -m --preview 'git diff --color=always {}' | xargs -0 -t -o git checkout -- "
13121223

.salesforcerc

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
#!/bin/bash
2+
3+
# Export a function as an entry point to PMD (which we use for Apex linting).
4+
# This lets us call "apexpmd" from child processes, like npm scripts
5+
function apexpmd() {
6+
/usr/local/Cellar/pmd/6.16.0/libexec/bin/run.sh pmd "$@"
7+
}
8+
export -f apexpmd
9+
10+
# 1 salesforci boi
11+
12+
# Find the value of any custom labels on a system matching a search pattern
13+
lbl() {
14+
if [[ -z "$1" ]] || [[ -z "$2" ]]; then
15+
echo "Usage: lbl [ORG_ID] [LABEL_REGEX]"
16+
return 1
17+
fi
18+
local result
19+
result=$(sfdx force:mdapi:listmetadata -m CustomLabel -u "${1}" --json)
20+
# shellcheck disable=SC2181
21+
if [ $? -ne 0 ];
22+
then
23+
echo "Error!"
24+
echo "${result}"
25+
else
26+
echo "All labels on ${1} matching '${2}' (case insensitive):"
27+
echo "${result}" | jq -r '.result[] | select(.fullName|test("'"${2}"'"; "i")) | .fullName' | while read -r line ; do
28+
stmt "${1}" "'${line}: ' + Label.${line}" quiet
29+
done
30+
fi
31+
}
32+
33+
# Execute an apex expression against an environment
34+
exp() {
35+
if [[ -z "$1" ]] || [[ -z "$2" ]]; then
36+
echo
37+
echo "${BOLD}NAME:${COLOR_RESET} exp"
38+
echo
39+
echo "${BOLD}DESCRIPTION:${COLOR_RESET} Execute an expression, and print the output. Takes the apex expression you pass in and wraps it in a System.debug() call.${COLOR_RESET}"
40+
echo
41+
echo "${BOLD}USAGE:${COLOR_RESET} exp [ORG_ID] [EXPRESSION_TO_EVALUATE] ['quiet' | 'q']"
42+
echo "Pass quiet or q as the last paremeter to supress notification messages"
43+
echo
44+
echo "${COLOR_RED}Error: ${COLOR_RESET} Expected two arguments to exp, the org ID and the expression."
45+
return 1
46+
fi
47+
48+
local apexCommand
49+
apexCommand='System.debug('"${2}"');'
50+
if [ "$3" != "quiet" ] && [ "$3" != "q" ]; then
51+
>&2 echo "${COLOR_BLUE}${BOLD}Executing:${COLOR_RESET}"
52+
>&2 echo "${COLOR_BLUE}${apexCommand}${COLOR_RESET}"
53+
>&2 echo
54+
fi
55+
56+
# Example apex output, to see what we're grepping for. Logs for the
57+
# multline command System.debug('a\nb'):
58+
# 11:38:56.11 (11521203)|EXECUTION_STARTED
59+
# 11:38:56.11 (11525424)|CODE_UNIT_STARTED|[EXTERNAL]|execute_anonymous_apex
60+
# 11:38:56.11 (11944606)|USER_DEBUG|[1]|DEBUG|a
61+
# b
62+
# 11:38:56.11 (11980694)|CUMULATIVE_LIMIT_USAGE
63+
# 11:38:56.11 (11980694)|LIMIT_USAGE_FOR_NS|(default)|
64+
# We need to find from the start of USER_DEBUG to the next non-debug line.
65+
# Notice "b" is put on a line by itself, making it tricky to include in output
66+
67+
sfdx force:apex:execute -u "${1}" -f /dev/stdin<<<"$apexCommand" | # Execute the expression inside a system.debug(). execute expects a file, so use <<< trick to make it seem like a file
68+
pcregrep -M 'USER_DEBUG(.|\n)+?([\d]{2}:[\d]{2}:[\d]{2})' | # find debug line, and try to search up to the next apex ouptut line, starting with dd:dd:dd
69+
sed '$d' | # remove the last line, which is the first non-debug line
70+
sed 's/.*\|//' # find everything after the last pipe, which will be the debugged output
71+
}
72+
73+
# Execute an apex expression against an environment
74+
stmt() {
75+
if [[ -z "$1" ]] || [[ -z "$2" ]]; then
76+
echo
77+
echo "${BOLD}NAME:${COLOR_RESET} stmt"
78+
echo
79+
echo "${BOLD}DESCRIPTION:${COLOR_RESET} Execute a statement or list of statements.${COLOR_RESET}"
80+
echo
81+
echo "${BOLD}USAGE:${COLOR_RESET} stmt [ORG_ID] [STATEMENTS_TO_EVALUATE] ['quiet' | 'q']"
82+
echo "Pass quiet or q as the last paremeter to supress notification messages"
83+
echo
84+
echo "${COLOR_RED}Error: ${COLOR_RESET} Expected two arguments to stmt, the org ID and the statements."
85+
return 1
86+
fi
87+
88+
local apexCommand
89+
apexCommand=${2}
90+
if [ "$3" != "quiet" ] && [ "$3" != "q" ]; then
91+
>&2 echo "${COLOR_BLUE}${BOLD}Executing:${COLOR_RESET}"
92+
>&2 echo "${COLOR_BLUE}${apexCommand}${COLOR_RESET}"
93+
>&2 echo
94+
fi
95+
96+
# Example apex output, to see what we're grepping for. Logs for the
97+
# multline command System.debug('a\nb'):
98+
# 11:38:56.11 (11521203)|EXECUTION_STARTED
99+
# 11:38:56.11 (11525424)|CODE_UNIT_STARTED|[EXTERNAL]|execute_anonymous_apex
100+
# 11:38:56.11 (11944606)|USER_DEBUG|[1]|DEBUG|a
101+
# b
102+
# 11:38:56.11 (11980694)|CUMULATIVE_LIMIT_USAGE
103+
# 11:38:56.11 (11980694)|LIMIT_USAGE_FOR_NS|(default)|
104+
# We need to find from the start of USER_DEBUG to the next non-debug line.
105+
# Notice "b" is put on a line by itself, making it tricky to include in output
106+
107+
sfdx force:apex:execute -u "${1}" -f /dev/stdin<<<"$apexCommand" # Execute the statement inside a system.debug(). execute expects a file, so use <<< trick to make it seem like a file
108+
}
109+
110+
alias orgls='open https://grhc.lightning.force.com/lightning/setup/DataManagementCreateTestInstance/home'
111+
112+
function orgid() {
113+
exp "$1" 'UserInfo.getOrganizationId()'
114+
}
115+
116+
function custbyjarvisid() {
117+
local comd
118+
if [[ -n "$2" ]]; then
119+
comd="[SELECT Id, Name FROM Account WHERE Customer_Account_ID__c = $2]"
120+
fi
121+
exp "$1" "$comd"
122+
}
123+
124+
function whodat() {
125+
exp "$1" "[SELECT username FROM User WHERE Id = '$2']"
126+
}
127+
128+
alias dstatus='open https://grhc--uat.lightning.force.com/lightning/setup/DeployStatus/home'
129+
alias tflags='open https://grhc--andrewdev.lightning.force.com/lightning/setup/ApexDebugLogs/home'
130+

code/settings.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"eslint.enable": true,
44
"javascript.validate.enable": false,
55
"editor.rulers": [80],
6-
"window.zoomLevel": 2,
6+
"window.zoomLevel": 1,
77
"files.exclude": {
88
"**/.DS_Store": true,
99
"**/.git": true,
@@ -88,5 +88,6 @@
8888
"editor.formatOnSave": true,
8989
"editor.defaultFormatter": "esbenp.prettier-vscode"
9090
},
91-
"editor.formatOnSave": true
91+
"editor.formatOnSave": true,
92+
"editor.multiCursorModifier": "ctrlCmd"
9293
}

0 commit comments

Comments
 (0)