{"record":{"id":"558d5501b4159ba9","repo":"sharkdp/fd","slug":"unable-to-get-shell-from-environment","errorCode":null,"errorMessage":"Unable to get shell from environment","messagePattern":"Unable to get shell from environment","errorType":"console","errorClass":"anyhow::Error","httpStatus":null,"severity":"warning","filePath":"src/cli.rs","lineNumber":782,"sourceCode":"    }\n\n    pub fn strip_cwd_prefix<P: FnOnce() -> bool>(&self, auto_pred: P) -> bool {\n        use self::StripCwdWhen::*;\n        self.no_search_paths()\n            && match self.strip_cwd_prefix.map_or(Auto, |o| o.unwrap_or(Always)) {\n                Auto => auto_pred(),\n                Always => true,\n                Never => false,\n            }\n    }\n\n    #[cfg(feature = \"completions\")]\n    pub fn gen_completions(&self) -> anyhow::Result<Option<Shell>> {\n        self.gen_completions\n            .map(|maybe_shell| match maybe_shell {\n                Some(sh) => Ok(sh),\n                None => {\n                    Shell::from_env().ok_or_else(|| anyhow!(\"Unable to get shell from environment\"))\n                }\n            })\n            .transpose()\n    }\n}\n\n/// Get the default number of threads to use, if not explicitly specified.\nfn default_num_threads() -> NonZeroUsize {\n    // If we can't get the amount of parallelism for some reason, then\n    // default to a single thread, because that is safe.\n    let fallback = NonZeroUsize::MIN;\n    // To limit startup overhead on massively parallel machines, don't use more\n    // than 64 threads.\n    let limit = NonZeroUsize::new(64).unwrap();\n\n    std::thread::available_parallelism()\n        .unwrap_or(fallback)\n        .min(limit)","sourceCodeStart":764,"sourceCodeEnd":800,"githubUrl":"https://github.com/sharkdp/fd/blob/b422e5d8c9cffaa1ae43ba68e7b97a60fb3e8ae5/src/cli.rs#L764-L800","documentation":"Thrown when fd's --gen-completions flag is invoked with no shell argument and the active shell cannot be auto-detected from the environment. fd delegates detection to clap_complete::Shell::from_env(), which inspects $SHELL (Unix) or registry/env conventions (Windows); if that returns None, generation cannot proceed. This only fires under the 'completions' cargo feature and only for the bare --gen-completions form.","triggerScenarios":"Running `fd --gen-completions` (no value) on a system where $SHELL is unset/empty, or in a container/cron/launchd context that strips environment variables. The code path is cli.rs:781, reached via Opts::gen_completions() when gen_completions is Some(None).","commonSituations":"CI runners and minimal Docker images that don't export $SHELL; systemd units; cron jobs; chroot/sandbox environments; macOS GUI-launched processes that lack a login shell env.","solutions":["Pass the shell explicitly: `fd --gen-completions bash` (or zsh/fish/powershell/elvish).","Export $SHELL before running: `SHELL=/bin/bash fd --gen-completions`.","If scripting in an unknown environment, always specify the target shell as an argument rather than relying on auto-detection."],"exampleFix":"# before (fails when $SHELL unset)\nfd --gen-completions\n\n# after (explicit shell)\nfd --gen-completions bash","handlingStrategy":"validation","validationCode":"if [ -z \"$SHELL\" ]; then\n  # caller supplies the shell explicitly\n  fd --gen-completions bash\nelse\n  fd --gen-completions\nfi","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass the target shell as an argument to --gen-completions in scripts.","Ensure login-shell environment ($SHELL) is present when auto-detection is intended.","Wrap completion generation in a Makefile target that pins the shell explicitly."],"tags":["completions","environment","shell","cli"],"backgroundTag":null,"analyzedSha":"b422e5d8c9cffaa1ae43ba68e7b97a60fb3e8ae5","analyzedAt":"2026-08-09T08:21:40.573Z","contentChangedAt":"2026-08-09T08:21:40.573Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}