环境变量#

所有 tgs 环境变量均为可选。它们会覆盖编译时的默认值或配置文件中的值。

变量列表#

VariableDescription
TGS_PROFILEActive profile name. Overrides .tgs.yaml but is overridden by --profile flag.
TGS_API_IDTelegram API ID. Overrides the value compiled into the binary.
TGS_API_HASHTelegram API Hash. Overrides the value compiled into the binary.
TGS_CONFIG_DIRConfig directory. Takes precedence over XDG_CONFIG_HOME. Default: $XDG_CONFIG_HOME/tgs, falling back to ~/.config/tgs.
TGS_DATA_DIRData directory for session databases. Takes precedence over XDG_DATA_HOME. Default: $XDG_DATA_HOME/tgs, falling back to ~/.local/share/tgs.
XDG_CONFIG_HOMEBase config directory (XDG spec). Used as $XDG_CONFIG_HOME/tgs when TGS_CONFIG_DIR is unset.
XDG_DATA_HOMEBase data directory (XDG spec). Used as $XDG_DATA_HOME/tgs when TGS_DATA_DIR is unset.

配置文件选择#

# Use the "work" profile for one command
TGS_PROFILE=work tgs whoami

# Use the "work" profile for the whole shell session
export TGS_PROFILE=work

完整优先级链详见配置文件解析顺序

API 凭证#

tgs 内置了编译时的 API 凭证,大多数用户无需设置。如果您从源码构建且未包含凭证,或者希望使用自己的 Telegram 应用凭证,可以进行覆盖。

export TGS_API_ID=12345
export TGS_API_HASH=abcdef1234567890abcdef1234567890
tgs login

my.telegram.org 获取 API 凭证。

自定义目录#

# Store config in a non-default location
export TGS_CONFIG_DIR=/etc/tgs

# Store sessions on a different volume
export TGS_DATA_DIR=/mnt/secure/tgs-data