summaryrefslogtreecommitdiff
path: root/topics/useful-shell-scripts.gmi
blob: 908928e902d954e49c9cc11c0ac269898b50655d (plain)
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
# Useful Shell Scripts

I make it a habit to put all my user-scripts in `~/bin/' and add that to my `$PATH'.  Another useful tip is to prepend all my scripts using a "," - this allows me to quickly take advantage of zsh's autocomplete.  For the curious, you could also adopt quiuy as part of the scripts - it has the advantage of adding more semantic meaning to your scripts.

Most of these scripts were borrowed from:

=> https://git.sr.ht/~whereiseveryone/dot/tree/master/item/bin

Here are the scripts that make me more efficient on the terminal:

* Run a script in the context of a directory: ",run-with-dir"

```
#!/bin/sh
set -eo pipefail

# Run a command in specific directory
run_within_dir() {
    target_dir="$1"
    previous_dir=$(pwd)
    shift
    cd $target_dir && "$@"
    cd $previous_dir
}

run_within_dir $@
```

If you are in `$HOME', you can do something like: "run-within-dir /tmp"

* Choose a guix profile on the fly: ",choose-profile":

```
#!/bin/env sh

# To run this use source!

GUIX_PROFILE="$(guix package --list-profiles | fzf --multi)"

export GUIX_PROFILE
. "$GUIX_PROFILE/etc/profile"
```

* Run magit from any terminal: ",magit".  You can take of fzf's autocomplete

```
#!/bin/env sh

emacsclient --eval "(projectile-vc \"$PWD/$@\")"
```

Should these scripts become too many, a repository will be created and a link added to point there.