Skip to content

Commit 63154bf

Browse files
authored
Merge pull request #11 from google/code-restructure
Code restructure
2 parents bd2194e + 99c9ad8 commit 63154bf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2344
-1945
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
g3upt/
22
g3doc/
3+
out/

README.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# purr
22

33
### Introduction
4-
purr is a zsh CLI tool for viewing and searching through Android logcat output. It leverages [fzf](https://github.com/junegunn/fzf) to provide a simple yet powerful user interface, fuzzy-finding capabilities, and much more.
4+
purr is a zsh CLI tool for viewing and searching through Android logcat output. It leverages [fzf](https://github.com/junegunn/fzf) to provide a simple yet powerful user interface, fuzzy-finding capabilities, and much more.
55

66
### Motivation
77
While Android Studio's logcat viewer is sufficient for most app development, it breaks down when exposed to situations such as terminal-only access or when multiple devices need to be accessed quickly. When performing development on the Android operating system itself, developers revert to using raw `adb logcat` in shell.
@@ -20,24 +20,27 @@ There's even a mode to search through `adb shell` results; no more grepping thro
2020

2121
https://github.com/google/purr/assets/126256142/fb41ec9d-f5a7-43be-98be-9d04ed7b536e
2222

23-
### Dependencies
24-
25-
`purr` currently functions on Ubuntu Linux and Mac on zsh. It will attempt to source an `fzf` version locally if possible, but requires version `0.40.0` or higher.
23+
### Installation
24+
1. Download the latest release version.
25+
2. Place the script in your PATH.
26+
3. If you need a copy program, also put the bundled osc52_copy program in your PATH.
2627

27-
If you do not have `fzf` `0.40.0` or higher locally, `purr` will use bundled `fzf` versions for `linux_x86_64`, `darwin_arm64` or `darwin_amd64` if applicable. If you have a different operating system, you need to download a `0.40.0` or higher `fzf` binary manually.
28+
### Compilation
29+
1. Clone the repo
30+
2. Run "make"
2831

29-
Support for Windows may be provided in future, but is not a current priority.
32+
### Dependencies
3033

31-
### Installation
32-
1. Clone the repo
33-
2. Add the scripts directory to your path
34-
3. Run using `purr`
34+
`purr` currently functions on Ubuntu Linux and Mac on `zsh`, and requires a local install of `fzf` with version `0.40.0` or higher, `perl`, and `adb`.
3535

36+
Some `purr` commands require a program to copy to clipboard. `purr` will check automatically for installations of `pbcopy`, `xsel`, and `wl-copy`. If the `COPY_PROGRAM` variable is set, purr will attempt to use it. If you are unsure of which copy program to use, a version of OSC52 copy is bundled and can be used if it is added to your path (and your terminal supports OSC52).
3637

37-
`purr` comes with two bundled programs:
38+
Support for Windows may be provided in future, but is not a current priority.
3839

39-
* `purr_osc52_copy` is a fallback to copy to the system clipboard through SSH and TMUX sessions.
40-
* `purr_fzf` is a bundled version of fzf `0.40.0` used if a higher version of `fzf` cannot be found.
40+
* [fzf](https://github.com/junegunn/fzf) [0.40.0+]
41+
* [zsh](https://github.com/zsh-users/zsh)
42+
* [adb](https://developer.android.com/studio/command-line/adb)
43+
* [perl](https://www.perl.org/)
4144

4245
### Guide
4346
`purr` includes a simple tool to help select the device serial from `adb devices`, or can read from the `$ANDROID_SERIAL` environment variable if set. Otherwise, `purr` has six command-line parameters:
@@ -53,8 +56,7 @@ Any other command-line parameters will print the help dialog.
5356

5457
Note that both `-a` and `-f` are read without validation; there is no guarantee that setting either parameter will not break `purr`.
5558

56-
#### Binds
57-
The following hotkeys can be used:
59+
### Hotkeys
5860

5961
#### General
6062
* Escape: Exits `purr`. Ctrl-c and other methods also work, but may take longer, and may not gracefully exit.
@@ -77,6 +79,8 @@ The following hotkeys can be used:
7779
* Ctrl-s: Enables scroll lock. While in scroll lock mode, your cursor will remain bound to the selected item as long as it remains in the search filter.
7880
* Ctrl-f: Shorthand for enabling scroll lock and clearing the query. This allows you to go to the surrounding context of a selected item. Scroll lock will end once you move your cursor.
7981
* Ctrl-j: Changes search modes between Chronological (default) and Relevance. This may be useful for fuzzy queries.
82+
83+
#### Querry
8084
* Ctrl-alt-s: Adds the selected tag to your query. If the tag already exists in your query, do nothing.
8185
* Ctrl-alt-d: Adds the inverse of the selected tag to your query. If the tag already exists in your query, remove it instead. Note that the inverse of the selected tag may also match non-tag lines in your log output.
8286

@@ -94,13 +98,14 @@ The following hotkeys can be used:
9498
#### History
9599
`purr` saves a query string to history once it has not been changed for more than 3.5 seconds. You can use the following hotkeys to access history:
96100

101+
* Ctrl-r: Show the full history menu.
97102
* Alt-shift-up: Move to the next entry in history.
98103
* Alt-shift-down: Move to the previous entry in history.
99104

100105
When scrolling through history with alt-shift-up or alt-shift-down, your position in the history will reset once a string has been in the query for 3.5 seconds.
101106

102107
#### Editor
103-
When you select a single line and press Ctrl-V, `purr` will open the selected line and surrounding context in a text editor. You can specify the text editor through the `$EDITOR` or `$EDITOR_PURR` environment variables; if no text editor is specified, `purr` will use `vim`.
108+
When you select a single line and press Ctrl-V, `purr` will open the selected line and surrounding context in a text editor. You can specify the text editor through the `$EDITOR` or `$EDITOR_PURR` environment variables; if no text editor is specified, `purr` will use `vim`.
104109

105110
Note that logcat uses ANSI color codes to display color, so an editor that supports these codes is recommended; for example, [AnsiEsc](https://www.vim.org/scripts/script.php?script_id=302) for `Vim`.
106111

@@ -110,11 +115,6 @@ If multiple lines are selected, only those selected lines will be opened in the
110115
1. Clone the repo
111116
2. Open in your favorite IDE/editor
112117

113-
### Dependencies
114-
* [fzf](https://github.com/junegunn/fzf) - Bundled
115-
* [zsh](https://github.com/zsh-users/zsh)
116-
* [adb](https://developer.android.com/studio/command-line/adb)
117-
118118
### Support
119119

120120
If you've found an error, please file an issue:

bundled/osc52_copy.sh

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/bin/sh
2+
3+
OSC_52_MAX_SEQUENCE="100000"
4+
5+
die() {
6+
echo "ERROR: $*"
7+
exit 1
8+
}
9+
10+
tmux_dcs() {
11+
printf '\033Ptmux;\033%s\033\\' "$1"
12+
}
13+
14+
screen_dcs() {
15+
local limit=256
16+
echo "$1" |
17+
sed -E "s:.{$((limit - 4))}:&\n:g" |
18+
sed -E -e 's:^:\x1bP:' -e 's:$:\x1b\\:' |
19+
tr -d '\n'
20+
}
21+
22+
print_seq() {
23+
local seq="$1"
24+
case ${TERM-} in
25+
screen*)
26+
if [ -n "${TMUX-}" ]; then
27+
tmux_dcs "${seq}"
28+
else
29+
screen_dcs "${seq}"
30+
fi
31+
;;
32+
tmux*)
33+
tmux_dcs "${seq}"
34+
;;
35+
*)
36+
echo "${seq}"
37+
;;
38+
esac
39+
}
40+
41+
b64enc() {
42+
base64 | tr -d '\n'
43+
}
44+
45+
osc_52_copy() {
46+
local str
47+
if [ $# -eq 0 ]; then
48+
str="$(b64enc)"
49+
else
50+
str="$(echo "$@" | b64enc)"
51+
fi
52+
if [ ${OSC_52_MAX_SEQUENCE} -gt 0 ]; then
53+
local len=${#str}
54+
if [ ${len} -gt ${OSC_52_MAX_SEQUENCE} ]; then
55+
die "selection too long to send to terminal:" \
56+
"${OSC_52_MAX_SEQUENCE} limit, ${len} attempted"
57+
fi
58+
fi
59+
print_seq "$(printf '\033]52;c;%s\a' "${str}")"
60+
}
61+
62+
set -e
63+
64+
osc_52_copy "$@"

makefile

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
OUTDIR?=$(CURDIR)/out
2+
SRCDIR?=$(CURDIR)/src
3+
RESDIR?=$(CURDIR)/res
4+
5+
PURRFILE ?=$(OUTDIR)/purr
6+
PURRFILE_TEMP ?=$(OUTDIR)/purr_temp
7+
8+
all: purr
9+
10+
.PHONY: purr
11+
12+
purr:
13+
mkdir -p $(OUTDIR)
14+
echo "" > $(PURRFILE)
15+
16+
# We first need the threading functions, since we use them as part of shell
17+
# env setup, specifically to create the cache files.
18+
cat $(SRCDIR)/threads/thread_background.sh >> "$(PURRFILE)"
19+
cat $(SRCDIR)/threads/thread_controller.sh >> "$(PURRFILE)"
20+
cat $(SRCDIR)/threads/thread_interface.sh >> "$(PURRFILE)"
21+
cat $(SRCDIR)/threads/thread_setup.sh >> "$(PURRFILE)"
22+
23+
# We can then cleanly do shell setup.
24+
cat $(SRCDIR)/shell/shell_utils.sh >> "$(PURRFILE)"
25+
cat $(SRCDIR)/shell/argument_parsing.sh >> "$(PURRFILE)"
26+
cat $(SRCDIR)/shell/shell_env_check.sh >> "$(PURRFILE)"
27+
cat $(SRCDIR)/shell/shell_env_init.sh >> "$(PURRFILE)"
28+
29+
# After we've validated the shell, we want to query for a serial number.
30+
cat $(SRCDIR)/serial/serial_picker.sh >> "$(PURRFILE)"
31+
cat $(SRCDIR)/serial/serial_interface.sh >> "$(PURRFILE)"
32+
cat $(SRCDIR)/serial/serial_init.sh >> "$(PURRFILE)"
33+
34+
# Load in all the UI utilities. We'll need these for setting up the fzf
35+
# environment in the next step.
36+
cat $(SRCDIR)/ui/ui_strings.sh >> "$(PURRFILE)"
37+
cat $(SRCDIR)/ui/ui_utils.sh >> "$(PURRFILE)"
38+
39+
# Finalizes the fzf environment; program is in a ready state at this point.
40+
# We just need to load in all the UI/UX elements from bindings.
41+
cat $(SRCDIR)/fzf_env/load_copy_program.sh >> "$(PURRFILE)"
42+
cat $(SRCDIR)/fzf_env/fzf_default_state.sh >> "$(PURRFILE)"
43+
44+
# Load the binding libraries; this is the main block of code for purr.
45+
# Order here isn't super important, but the stream bindings need to be
46+
# at the very bottom after the command suites are fully initialized.
47+
cat $(SRCDIR)/bindings/command_suites.sh >> "$(PURRFILE)"
48+
cat $(SRCDIR)/bindings/copy_bindings.sh >> "$(PURRFILE)"
49+
cat $(SRCDIR)/bindings/history_bindings.sh >> "$(PURRFILE)"
50+
cat $(SRCDIR)/bindings/input_trim_bindings.sh >> "$(PURRFILE)"
51+
cat $(SRCDIR)/bindings/misc_bindings.sh >> "$(PURRFILE)"
52+
cat $(SRCDIR)/bindings/mode_bindings.sh >> "$(PURRFILE)"
53+
cat $(SRCDIR)/bindings/navigation_bindings.sh >> "$(PURRFILE)"
54+
cat $(SRCDIR)/bindings/preview_bindings.sh >> "$(PURRFILE)"
55+
cat $(SRCDIR)/bindings/query_bindings.sh >> "$(PURRFILE)"
56+
cat $(SRCDIR)/bindings/stream_bindings.sh >> "$(PURRFILE)"
57+
58+
# Load the execution loop that actually makes things happen.
59+
cat $(SRCDIR)/execution_loop.sh >> "$(PURRFILE)"
60+
61+
# Remove comments/shebangs.
62+
sed -i -e '/^[ \t]*#/d' "$(PURRFILE)"
63+
64+
# Add one shebang and the copyright notice.
65+
# We need a temp file since cat can't do it in-place.
66+
cat $(RESDIR)/header/purr_header.txt $(PURRFILE) > $(PURRFILE_TEMP)
67+
68+
# Undo the temp file swap
69+
mv -f $(PURRFILE_TEMP) $(PURRFILE)
70+
71+
# Grant execution permission.
72+
chmod 777 $(PURRFILE)
73+
74+
.PHONY: clean
75+
76+
clean:
77+
[ -e $(OUTDIR) ] && rm -r $(OUTDIR) || true

0 commit comments

Comments
 (0)