Skip to main content

fish_functions/README.md

1# fish_functions
3This is a collection of functions for the Fish shell, which are [automatically loaded][functions].
4When I call one of these functions for the first time, Fish looks for the corresponding file in this folder and loads the function from there.
6[functions]: https://fishshell.com/docs/current/language.html#autoloading-functions
8<!-- [[[cog
10# This adds the root of the repo to the PATH, which has cog_helpers.py
11from os.path import abspath, basename, dirname
12import sys
14sys.path.append(abspath(dirname(dirname("."))))
16import glob
17import shlex
19import cog
21import cog_helpers
23folder_name = "fish_functions"
25functions = []
27for f in sorted(glob.glob("fish_functions/*.fish")):
29 # Look for the line in the file that defines the function.
30 #
31 # e.g. if the file is called 'tmpdir.fish', look for the line that
32 # starts 'function tmpdir'
33 function_name = basename(f).replace('.fish', '')
34 definition_line = next(
35 line
36 for line in open(f)
37 if line.startswith(f'function {function_name}')
38 )
40 # Now split the definition line into components
41 components = shlex.split(definition_line)
42 try:
43 description_flag = components.index("--description")
44 except ValueError:
45 raise ValueError(f"No --description flag for {function_name}")
46 description = components[description_flag + 1]
48 functions.append({"name": basename(f), "description": description})
50cog_helpers.create_description_table(folder_name=folder_name, scripts=functions)
51]]] -->
52<dl>
53 <dt>
54 <a href="https://github.com/alexwlchan/scripts/blob/main/fish_functions/add_repo_to_path.fish">
55 <code>add_repo_to_path.fish</code>
56 </a>
57 </dt>
58 <dd>
59 Add a folder in my ~/repos directory to my PATH
60 </dd>
62 <dt>
63 <a href="https://github.com/alexwlchan/scripts/blob/main/fish_functions/append_to_file_if_not_exists.fish">
64 <code>append_to_file_if_not_exists.fish</code>
65 </a>
66 </dt>
67 <dd>
68 Append a line to a file, but only if it's not already there
69 </dd>
71 <dt>
72 <a href="https://github.com/alexwlchan/scripts/blob/main/fish_functions/auto_activate_venv.fish">
73 <code>auto_activate_venv.fish</code>
74 </a>
75 </dt>
76 <dd>
77 Auto activate/deactivate virtualenv when I change directories
78 </dd>
80 <dt>
81 <a href="https://github.com/alexwlchan/scripts/blob/main/fish_functions/fish_prompt.fish">
82 <code>fish_prompt.fish</code>
83 </a>
84 </dt>
85 <dd>
86 Write out the prompt
87 </dd>
89 <dt>
90 <a href="https://github.com/alexwlchan/scripts/blob/main/fish_functions/forget_last_command.fish">
91 <code>forget_last_command.fish</code>
92 </a>
93 </dt>
94 <dd>
95 Remove the last-typed command from my fish history
96 </dd>
98 <dt>
99 <a href="https://github.com/alexwlchan/scripts/blob/main/fish_functions/github-clone.fish">
100 <code>github-clone.fish</code>
101 </a>
102 </dt>
103 <dd>
104 Clone a GitHub repository into my ~/repos directory
105 </dd>
107 <dt>
108 <a href="https://github.com/alexwlchan/scripts/blob/main/fish_functions/go.fish">
109 <code>go.fish</code>
110 </a>
111 </dt>
112 <dd>
113 Remind me to use ./tool/go in Tailscale repos
114 </dd>
116 <dt>
117 <a href="https://github.com/alexwlchan/scripts/blob/main/fish_functions/pip_sync.fish">
118 <code>pip_sync.fish</code>
119 </a>
120 </dt>
121 <dd>
122 Make a virtualenv dependencies look like requirements.txt
123 </dd>
125 <dt>
126 <a href="https://github.com/alexwlchan/scripts/blob/main/fish_functions/reload_fish_config.fish">
127 <code>reload_fish_config.fish</code>
128 </a>
129 </dt>
130 <dd>
131 Load the latest version of my fish config
132 </dd>
134 <dt>
135 <a href="https://github.com/alexwlchan/scripts/blob/main/fish_functions/tmpdir.fish">
136 <code>tmpdir.fish</code>
137 </a>
138 </dt>
139 <dd>
140 Create and switch into a temporary directory
141 </dd>
143 <dt>
144 <a href="https://github.com/alexwlchan/scripts/blob/main/fish_functions/venv.fish">
145 <code>venv.fish</code>
146 </a>
147 </dt>
148 <dd>
149 Create and activate a new virtual environment
150 </dd>
151</dl>
152<!-- [[[end]]] (sum: FW10hKks6J) -->