{"id":16593569,"url":"https://github.com/mattmc3/zfunctions","last_synced_at":"2025-10-29T10:31:44.641Z","repository":{"id":53396848,"uuid":"231447744","full_name":"mattmc3/zfunctions","owner":"mattmc3","description":"Use a zfunctions directory for lazy loaded (autoload) zsh functions - similar to fish shell","archived":false,"fork":false,"pushed_at":"2024-03-06T16:25:26.000Z","size":32,"stargazers_count":17,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-03-07T17:21:11.913Z","etag":null,"topics":["zsh","zsh-plugin"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mattmc3.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2020-01-02T19:39:37.000Z","updated_at":"2024-02-25T10:19:02.000Z","dependencies_parsed_at":"2024-03-06T17:00:56.838Z","dependency_job_id":null,"html_url":"https://github.com/mattmc3/zfunctions","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattmc3%2Fzfunctions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattmc3%2Fzfunctions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattmc3%2Fzfunctions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattmc3%2Fzfunctions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mattmc3","download_url":"https://codeload.github.com/mattmc3/zfunctions/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219857783,"owners_count":16556050,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["zsh","zsh-plugin"],"created_at":"2024-10-11T23:27:13.952Z","updated_at":"2025-10-29T10:31:39.337Z","avatar_url":"https://github.com/mattmc3.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# zfunctions plugin\n\nUse a `$ZDOTDIR/functions` directory to store lazy-loaded zsh function files.\n\nThis plugin is similar in concept to the [fish] functions directory.\n\n## Description\n\nThis plugin will enable a directory for you to store function files, and adds that directory to your Zsh `fpath` variable.\nAny file placed in this directory should contain the innards of a single function definition.\nThese files will then be \"autoloaded\" (aka: lazy loaded) by Zsh into a function of the same name upon their first call.\nThe lazy-loading functionality is a built-in feature of Zsh called [function autoloading][zsh-autoload].\n\nYour functions path by default is: `${ZDOTDIR:-$HOME/.config/zsh}/functions`.\nHowever, you can optionally override the path by setting the `$ZFUNCDIR` value:\n\n```zsh\nZFUNCDIR=/path/to/my/lazy/zfunctions\n```\n\n## Features\n\nThe following functions are defined by this plugin:\n\n| Functions | Arguments     | Description                                            |\n|:----------|:--------------|:-------------------------------------------------------|\n| funced    | \\\u003cfunc-name\\\u003e | edit the function specified                            |\n| funcsave  | \\\u003cfunc-name\\\u003e | save a function to your configured functions directory |\n| funchelp  | \\\u003cfunc-name\\\u003e | print function help, designated via '##?' comments     |\n\n**Note:**\nAdditionally, the built-in zsh `functions` command will list all the zsh functions that are defined.\nThe built-in `function` keyword will allow you to define a new function.\n\n## Example\n\nFirst, make sure you have loaded the zfunctions plugin and started a new zsh session.\nYou can verify that zfunctions is enabled by running the following:\n\n```zsh\n$ (( $+functions[funcsave] )) \u0026\u0026 echo \"zfunctions loaded\" || echo \"zfunctions not loaded\"\nzfuncions loaded\n```\n\nNext, let's set a $ZFUNCDIR variable for our examples\n```zsh\nZFUNCDIR=${ZDOTDIR:-$HOME/.config/zsh}/functions\n```\n\nNow, let's make a quick function to test with called 'foo'.\n\nThe 'foo' function should always print \"bar\" and sometimes also print \"baz\".\n\nFrom a zsh prompt, define this function:\n\n```zsh\n# 'foo' with comments and custom formatting\nfunction foo() {\n    # print bar\n    echo \"bar\"\n    # and sometimes baz\n    if [[ $[${RANDOM}%2] -eq 0 ]]; then\n        echo \"baz\"\n    fi\n}\n```\n\nNext, we can save the function.\n\n```zsh\nfuncsave foo\n```\n\nNow you should have a function file called \"foo\" in `$ZFUNCDIR`. Let's verify:\n\n```zsh\ncat $ZFUNCDIR/foo\n```\n\nNotice that the function was reformatted and also that only the function *internals* are saved to the \"foo\" file, not the function name definition\n(ie: the \"`function foo() {`\" part is purposely missing).\n\n```zsh\n# contents of $ZFUNCDIR/foo\necho \"bar\"\nif [[ $[${RANDOM}%2] -eq 0 ]]\nthen\n    echo \"baz\"\nfi\n```\n\nRun `zsh` to start a new zsh session to show how lazy loading works.\n\n```zsh\nzsh\n```\n\nNow, check out the function definition for `foo` by using the `functions`\nbuilt-in (notice the trailing \"s\" on the word function**s**):\n\n```zsh\nfunctions foo\n```\n\nYou should see this:\n\n```zsh\nfoo () {\n    # undefined\n    builtin autoload -XUz ~/.config/zsh/functions\n}\n```\n\nNow execute the `foo` function once (or do it a few times for fun):\n\n```zsh\n# outputs bar, and sometimes baz\n$ foo\nbar\n$ foo\nbar\nbaz\n$ foo\nbar\n```\n\nNow go back and run `functions foo` again and check out the results...\nThe function definition is now filled in from the `foo` file in your `$ZFUNCDIR`.\n\n```zsh\nfoo() {\n    echo \"bar\"\n    if [[ $[${RANDOM}%2] -eq 0 ]]\n    then\n        echo \"baz\"\n    fi\n}\n```\n\nYou can edit the 'foo' function by using `funced`:\n\n```zsh\n# edit the foo function\nfunced foo\n\n# or, make a new one entirely\nfunced bar\n```\n\nThat's it! Note that you do not need to use `funcsave` or `funced` if you don't prefer to.\nAdding files to `$ZFUNCDIR` yourself is also an option. Just remember that your function\nfiles should be named without a file extension (ie: foo, not foo.zsh), and should not\ncontain the function declaration part (ie: `function foo() {`).\n\nHere's a great first function to create called \"up\".\nStart by typing `funced up` and add this to the file:\n\n```zsh\n### $ZFUNCDIR/up\n# goes up any number of directories\nif [[ \"$#\" \u003c 1 ]] ; then\n    cd ..\nelse\n    local rpt=$(printf \"%${1}s\")\n    local cdstr=${rpt// /..\\/}\n    cd $cdstr\nfi\n```\n\nHave fun building your zsh function library!\n\n[omz]: https://github.com/ohmyzsh/ohmyzsh\n[fish]: https://fishshell.com\n[zsh-autoload]: http://zsh.sourceforge.net/Doc/Release/Functions.html#Autoloading-Functions\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattmc3%2Fzfunctions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmattmc3%2Fzfunctions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattmc3%2Fzfunctions/lists"}