Skip to content

Commit

Permalink
docs: Update environment variables and history section
Browse files Browse the repository at this point in the history
  • Loading branch information
LangLangBart committed May 12, 2024
1 parent a8eca1d commit 7438a8f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 40 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ repos:
pass_filenames: false
files: gh-find-code
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/crate-ci/typos
rev: v1.19.0
rev: v1.21.0
hooks:
- id: typos
args: [--format, brief, --write-changes]
Expand Down Expand Up @@ -59,7 +59,7 @@ repos:
name: markdown link check
args: [--quiet]
- repo: https://github.com/commitizen-tools/commitizen
rev: v3.20.0
rev: v3.25.0
hooks:
- id: commitizen
stages: [commit-msg]
21 changes: 9 additions & 12 deletions gh-find-code
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ if ((GHFC_DEBUG_MODE)); then
store_gh_search_debug="${debug_directory}/gh_search_debug"
store_grep_extended_debug="${debug_directory}/grep_extended_debug"

# Redirect stdout and stderr to both the terminal and the debug file.
exec &> >(command tee -a "$store_all_debug")

# 'GH_DEBUG' is useful for understanding the reasons behind failed GitHub API calls.
export GH_DEBUG=api

Expand Down Expand Up @@ -66,8 +63,8 @@ error_handler() {
--language bash \
--line-range $((lineno - 3)):+7 \
--style numbers \
--terminal-width $((${COLUMNS:-$(tput cols)} - 4)) "${BASH_SOURCE[0]}" \
--wrap never |
--terminal-width $((${COLUMNS:-$(tput cols)} - 4)) \
--wrap never -- "${BASH_SOURCE[0]}" |
command sed 's/^/ /;4s/ />>/'
} >&2
exit "$exit_code"
Expand Down Expand Up @@ -885,10 +882,10 @@ main() {
trap - ERR

# NOTE: The 'change-preview-window' action in 'transform' should precede 'change-preview'.
# NOTE: In the transform action, placeholders and functions using placeholders as arguments must be
# escaped, e.g. '\view_contents \{}', but not 'print_help_text'.
# TODO: The hotkeys 'ctrl-t' and '?' may cause issues if used during certain operations; a solution
# is needed to address this complexity.
# NOTE: In the transform action, placeholders and functions using placeholders as arguments must
# be escaped, e.g. '\view_contents \{}', but not 'print_help_text'.
# TODO: The hotkeys 'ctrl-t' and '?' may cause issues if used during certain operations; a
# solution is needed to address this complexity.
fzf_basic_style \
--bind "change:first+reload:command sleep 0.5; gh_query" \
--bind "resize:transform:preview_transformer" \
Expand All @@ -901,9 +898,9 @@ main() {
--bind 'ctrl-r:reload:gh_user_limit=100 gh_query' \
--bind 'ctrl-space:execute:view_history_commands' \
--bind "ctrl-t:transform:[[ ! \$FZF_PROMPT == \"$fzf_prompt_fuzzyAB\" ]] &&
echo 'unbind(change)+change-prompt($fzf_prompt_fuzzyAB)+enable-search+transform-query:echo \{fzf:query} > $store_search_string; command cat $store_fuzzy_search_string' ||
echo 'rebind(change)+change-prompt($default_fzf_prompt)+disable-search+transform-query:echo \{fzf:query} > $store_fuzzy_search_string; command cat $store_search_string'" \
--bind 'ctrl-x:execute-silent:open_query_in_browser {fzf:query}' \
echo 'unbind(change)+change-prompt($fzf_prompt_fuzzyAB)+enable-search+transform-query:echo \{q} > $store_search_string; command cat $store_fuzzy_search_string' ||
echo 'rebind(change)+change-prompt($default_fzf_prompt)+disable-search+transform-query:echo \{q} > $store_fuzzy_search_string; command cat $store_search_string'" \
--bind 'ctrl-x:execute-silent:open_query_in_browser {q}' \
--bind $'enter:execute:[[ $FZF_MATCH_COUNT -ge 1 ]] && view_contents {}' \
--bind 'esc:become:' \
--bind "tab:change-prompt($default_fzf_prompt)+change-preview(view_contents {})+change-preview-window:hidden:hidden|+{1}+3/3" \
Expand Down
49 changes: 24 additions & 25 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,26 @@ gh ext remove LangLangBart/gh-find-code

---

## 🌐 Environment Variables

**Table 1: Environment Variables Utilized**

| Variable | Purpose | Default |
| ------------------ | -------------------------------------- | ------------------ |
| `BAT_THEME` | Preview theme for syntax highlighting. | `Monokai Extended` |
| `EDITOR` | Editor to open selected files. | System-specific |
| `PAGER` | Pager for file viewing. | System-specific |

**Table 2: Environment Variables Defined and Utilized**

| Variable | Purpose | Default |
| -------------------- | ----------------------------- | -------------------------------------------- |
| `GHFC_DEBUG_MODE` | Enable debug mode | `0` (Disabled) |
| `GHFC_HISTORY_FILE` | Custom location | `${BASH_SOURCE%/*}/gh_find_code_history.txt` |
| `GHFC_HISTORY_LIMIT` | Max number of stored commands | `500` |

---

## 💁 TIPS

### Alias
Expand All @@ -98,10 +118,7 @@ alias ghfc='BAT_THEME="Dracula" EDITOR="vim" gh find-code'
```

### Bat
- The color scheme of the preview is determined by the `BAT_THEME` environment
variable. If not explicitly set by the user, the theme defaults to `Monokai
Extended`.

- Set `BAT_THEME` to change the preview color scheme:
```sh
# To view all default themes
bat --list-themes --color=never
Expand All @@ -110,15 +127,6 @@ bat --list-themes --color=never
BAT_THEME="Dracula" gh find-code
```

### Debugging
- To activate debug mode, set `GHFC_DEBUG_MODE=1`. This enables `xtrace` and
logs outputs to a file, with the file's location displayed after script
execution.

```bash
GHFC_DEBUG_MODE=1 gh find-code
```

### Editor
- The extension uses the `EDITOR` environment variable to determine in which
editor the selected file will be opened, works with `nano`, `nvim/vi/vim`,
Expand Down Expand Up @@ -147,21 +155,12 @@ export FZF_DEFAULT_OPTS="
- **NOTE:** [How to use ALT commands in a terminal on macOS?](https://superuser.com/questions/496090/how-to-use-alt-commands-in-a-terminal-on-os-x)

### History
- Recent commands can be viewed with <kbd>⌃ Control</kbd> + <kbd>Space</kbd>.
- The history file stores successfully completed unique commands, one can
specify a custom location using the `GHFC_HISTORY_FILE` environment variable.
- The history file stores successfully completed unique commands.
- Customize history file location and limit:

```bash
# Default location: ${BASH_SOURCE%/*}/gh_find_code_history.txt
```sh
# Specify a custom location for the history file
GHFC_HISTORY_FILE="/custom/location/history.txt" gh find-code
```

- In case of duplicates, only the most recent entry is preserved. The default
maximum number of command entries is **500**, but this can be adjusted by
setting the `GHFC_HISTORY_LIMIT` variable.

```bash
# Set the maximum number of stored commands to 1000
GHFC_HISTORY_LIMIT="1000" gh find-code
```
Expand Down

0 comments on commit 7438a8f

Please sign in to comment.