Documentation
¶
Index ¶
- func Add_to_path(path_to_add string) error
- func Add_to_ps_module_path(input_path string) error
- func Choco_install(package_name string) error
- func Convert_blob_to_raw_github_url(blob_url string) (string, error)
- func Create_desktop_shortcut(target_path, shortcut_name, description string, window_style int, ...) error
- func Do_not_hide_search_box(restartExplorer bool) error
- func Do_not_show_file_extensions(restartExplorer bool) error
- func Do_not_show_hidden_files(restartExplorer bool) error
- func Do_not_use_24_hour_format() error
- func Download_file(destination_path string, url string) error
- func Enable_SSH() error
- func Enable_SSH_through_firewall() error
- func Exclude_from_Microsoft_Windows_Defender(path_to_exclude string) error
- func Expand_windows_env(input string) string
- func Extract_password_protected_zip(src, dest, password string) error
- func Extract_zip(src, dest string) error
- func File_exists(path string) bool
- func Get_file_size(path string) (int64, error)
- func Get_primary_ipv4_address() (string, error)
- func Hide_search_box(restartExplorer bool) error
- func Install_Java() error
- func Install_choco() error
- func Is_Choco_installed() bool
- func Is_Java_installed() bool
- func Remove_from_path(path_to_remove string) error
- func Remove_from_ps_module_path(input_path string) error
- func Reset_long_date_pattern() error
- func Reset_short_date_pattern() error
- func Reset_time_pattern() error
- func Restart_file_explorer() error
- func Seconds_in_taskbar(restartExplorer bool) error
- func Set_24_hour_format() error
- func Set_dark_mode(restartExplorer bool) error
- func Set_first_day_of_week_Monday() error
- func Set_first_day_of_week_Sunday() error
- func Set_light_mode(restartExplorer bool) error
- func Set_long_date_pattern() error
- func Set_short_date_pattern() error
- func Set_start_menu_to_center() error
- func Set_start_menu_to_left() error
- func Set_system_environment_variable(variable_name string, variable_value string) error
- func Set_time_pattern() error
- func Show_file_extensions(restartExplorer bool) error
- func Show_hidden_files(restartExplorer bool) error
- func Take_seconds_out_of_taskbar(restartExplorer bool) error
- func Winget_install(package_name string, package_id string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Add_to_path ¶
Add_to_path adds the given path to the top of the system PATH (HKLM) if not already present. It expands environment variables, removes redundant entries (like %SystemRoot%), avoids duplicates, and broadcasts the environment change to Explorer.
func Add_to_ps_module_path ¶
Add_to_ps_module_path resolves the appropriate parent directory based on a given file or folder path and adds it to the system-wide PSModulePath
Supported input: - .psm1 or .psd1 file => adds the grandparent directory - folder with only .psm1 or .psd1 files => adds parent of that folder - otherwise adds folder itself
func Choco_install ¶
Choco_install installs the given Chocolatey package and checks if it was installed successfully.
func Convert_blob_to_raw_github_url ¶
Convert_blob_to_raw_github_url transforms a GitHub "blob" URL into a "raw" content URL.
GitHub's web interface often shows files using a URL like:
https://github.com/{user}/{repo}/blob/{branch}/{path/to/file}
But to access the raw file directly through GitHub (still using the github.com domain), the equivalent raw content URL is:
https://github.com/{user}/{repo}/raw/{branch}/{path/to/file}
This function performs the necessary transformation by replacing the "/blob/" segment in the URL with "/raw/".
For example:
Input: https://github.com/user/repo/blob/main/script.ps1 Output: https://github.com/user/repo/raw/main/script.ps1
Parameters:
- blob_url: the GitHub "blob" URL to convert
Returns:
- The corresponding "raw" content URL
- An error if the input does not contain the expected "/blob/" segment
func Create_desktop_shortcut ¶
func Create_desktop_shortcut(target_path, shortcut_name, description string, window_style int, all_users bool) error
Create_desktop_shortcut creates a .lnk shortcut on the desktop. It accepts the target path, shortcut name (optional), description (optional), window style (3 = maximized), and allUsers flag.
func Do_not_hide_search_box ¶
Do_not_hide_search_box sets SearchboxTaskbarMode = 2 to show the full search box on the taskbar. If restartExplorer is true, Explorer will be restarted to apply the change.
func Do_not_show_file_extensions ¶
Do_not_show_file_extensions sets HideFileExt = 1 to hide file extensions. If restartExplorer is true, Explorer is restarted to apply the change immediately.
func Do_not_show_hidden_files ¶
Do_not_show_hidden_files sets Hidden = 2 to hide hidden files in File Explorer. If restartExplorer is true, Explorer will be restarted to apply the change immediately.
func Do_not_use_24_hour_format ¶
func Do_not_use_24_hour_format() error
Do_not_use_24_hour_format configures Windows to use 12-hour time by setting iTime = 0.
func Download_file ¶
Download_file downloads a file from the given URL and saves it to the specified destination path.
Parameters:
- destination_path: The full file path (including filename) where the downloaded content will be saved.
- url: The HTTP or HTTPS URL from which to download the file.
Returns:
- An error if the download, file creation, or writing fails; otherwise, nil.
Example:
err := Download_file("C:\\downloads\\example.exe", "https://example.com/file.exe") if err != nil { log.Fatalf("Download failed: %v", err) }
func Enable_SSH ¶
func Enable_SSH() error
Enable_SSH ensures the "sshd" service is set to Automatic and Running.
func Enable_SSH_through_firewall ¶
func Enable_SSH_through_firewall() error
Enable_SSH_through_firewall ensures that TCP port 22 is allowed in the firewall for all profiles.
func Exclude_from_Microsoft_Windows_Defender ¶
Exclude_from_Microsoft_Windows_Defender excludes the given file or folder from Microsoft Defender.
If a file is given, its parent folder is excluded instead. This requires administrator privileges.
Parameters:
- path_to_exclude: Absolute path to a file or folder to exclude.
Returns:
- An error if exclusion fails; nil otherwise.
func Expand_windows_env ¶ added in v3.3.3
Expand_windows_env expands environment variables using the Windows API. For example, %SystemRoot% becomes C:\Windows.
func Extract_password_protected_zip ¶
Extract_password_protected_zip extracts a password-protected ZIP archive using AES or ZipCrypto.
Parameters:
- src: full path to the .zip archive
- dest: directory where the files should be extracted
- password: the password used to decrypt the archive
Returns:
- error if extraction fails, otherwise nil
func Extract_zip ¶
Extract_zip extracts a ZIP archive specified by src into the destination directory dest.
It protects against Zip Slip attacks by ensuring all extracted paths are within dest.
Parameters:
- src: Full path to the ZIP archive.
- dest: Destination directory where the contents will be extracted.
Returns:
- An error if extraction fails, or nil on success.
func File_exists ¶
File_exists checks if a file exists and is not a directory.
func Get_file_size ¶ added in v3.9.0
Get_file_size returns the size in bytes of the specified path. If the path is a regular file, its size is returned directly. If the path is a directory, the function walks through all files and returns the cumulative size of all non-directory files within it.
Parameters:
- path: The path to the file or directory.
Returns:
- int64: Total size in bytes.
- error: Any error encountered while accessing the file system.
Example:
size, err := Get_file_size("C:\\Users\\Administrator\\Desktop") if err != nil { log.Fatal(err) } fmt.Println("Total size:", size)
func Get_primary_ipv4_address ¶ added in v3.6.0
Get_primary_ipv4_address returns the most appropriate local IPv4 address from the available network interfaces.
It prioritizes interfaces whose names contain preferred keywords such as "Wi-Fi", "Ethernet", or "Tailscale", and excludes interfaces that are likely virtual, loopback, or otherwise irrelevant, such as those containing "VMware", "Virtual", "Bluetooth", "Loopback", "OpenVPN", or "Disconnected".
The function performs the following steps:
- Lists all active, non-loopback interfaces.
- Filters out interfaces matching any excluded keywords.
- Searches for an interface whose name contains a preferred keyword.
- Falls back to any remaining valid interface if no preferred one is found.
- Returns the first usable IPv4 address found.
Returns the IPv4 address as a string, or an empty string if none are found. If an error occurs while listing interfaces, it is returned.
func Hide_search_box ¶
Hide_search_box sets SearchboxTaskbarMode = 0 to hide the taskbar search box. If restartExplorer is true, Explorer will be restarted to apply the change.
func Install_Java ¶
func Install_Java() error
Install_Java ensures Java is installed by checking Is_Java_installed(). If not found, it installs the temurin21 JDK via Chocolatey, verifies the result, and sets JAVA_HOME to the default installation path using PowerShell.
func Install_choco ¶
func Install_choco() error
Install_choco installs Chocolatey using the official PowerShell script. It takes no arguments and logs output to the standard logger. You could have Install_Choco check if choco is installed before installing. Then you could just call Install_Choco, and it would handle the details of whether Choco was installed or not. Install_choco installs Chocolatey if it is not already installed. It logs all steps to the standard logger.
func Is_Choco_installed ¶
func Is_Choco_installed() bool
Is_Choco_installed checks if Chocolatey is installed. It returns true if choco.exe is found in PATH or at the default location.
func Is_Java_installed ¶
func Is_Java_installed() bool
Is_Java_installed checks if both java.exe and javac.exe are available in PATH, or in the default Eclipse Adoptium installation directory.
func Remove_from_path ¶
Remove_from_path removes the given path from the system PATH if present. It normalizes the path, modifies HKLM registry, and broadcasts environment changes.
func Remove_from_ps_module_path ¶
Remove_from_ps_module_path resolves the appropriate parent directory based on a given file or folder path and removes it from the system-wide PSModulePath.
func Reset_long_date_pattern ¶
func Reset_long_date_pattern() error
Reset_long_date_pattern resets the long date pattern to the default "dddd, MMMM d, yyyy" and broadcasts the change to the system.
func Reset_short_date_pattern ¶
func Reset_short_date_pattern() error
Reset_short_date_pattern resets the short date pattern to "M/d/yyyy" and broadcasts the change to the system.
func Reset_time_pattern ¶
func Reset_time_pattern() error
Reset_time_pattern resets long/short time format and separator to system defaults.
func Restart_file_explorer ¶ added in v3.7.0
func Restart_file_explorer() error
Restart_file_explorer uses PowerShell to stop and restart Windows File Explorer, and waits until explorer.exe is running again.
func Seconds_in_taskbar ¶
Seconds_in_taskbar enables seconds on the taskbar clock by setting ShowSecondsInSystemClock = 1. If restartExplorer is true, Explorer will be restarted to apply the change.
func Set_24_hour_format ¶
func Set_24_hour_format() error
Set_24_hour_format configures Windows to use 24-hour time by setting iTime = 1.
func Set_dark_mode ¶
Set_dark_mode sets Windows to dark mode for both system and apps. If restartExplorer is true, it restarts Explorer to apply the change.
func Set_first_day_of_week_Monday ¶
func Set_first_day_of_week_Monday() error
Set_first_day_of_week_Monday sets Monday as the first day of the week in Windows regional settings.
func Set_first_day_of_week_Sunday ¶
func Set_first_day_of_week_Sunday() error
Set_first_day_of_week_Sunday sets Sunday as the first day of the week in Windows regional settings.
func Set_light_mode ¶
Set_light_mode sets Windows to light mode for both system and apps. If restartExplorer is true, it restarts Explorer to apply the change.
func Set_long_date_pattern ¶
func Set_long_date_pattern() error
Set_long_date_pattern sets the long date pattern to "yyyy-MM-dd-dddd" and broadcasts the change to the system.
func Set_short_date_pattern ¶
func Set_short_date_pattern() error
Set_short_date_pattern sets the short date pattern to "yyyy-MM-dd-dddd" and broadcasts the change to the system.
func Set_start_menu_to_center ¶
func Set_start_menu_to_center() error
Set_start_menu_to_center sets the Windows 11 taskbar alignment to the center by writing TaskbarAl=1 in the registry and restarting Explorer.
func Set_start_menu_to_left ¶
func Set_start_menu_to_left() error
Set_start_menu_to_left sets the Windows 11 taskbar alignment to the left by writing TaskbarAl=0 in the registry and restarting Explorer.
func Set_system_environment_variable ¶ added in v3.5.0
Set_system_environment_variable sets a system-wide environment variable in the registry under HKLM. It also broadcasts the environment change so that Explorer and other processes recognize the update.
func Set_time_pattern ¶
func Set_time_pattern() error
Set_time_pattern sets custom time patterns and separator: - Long time: "HH.mm.ss" - Short time: "HH.mm.ss" - Separator: "."
func Show_file_extensions ¶
Show_file_extensions sets HideFileExt = 0 to make file extensions visible. If restartExplorer is true, Explorer is restarted to apply the change immediately.
func Show_hidden_files ¶
Show_hidden_files sets Hidden = 1 to show hidden files in File Explorer. If restartExplorer is true, Explorer will be restarted to apply the change immediately.
func Take_seconds_out_of_taskbar ¶
Take_seconds_out_of_taskbar disables seconds on the taskbar clock by setting ShowSecondsInSystemClock = 0. If restartExplorer is true, Explorer will be restarted to apply the change.
func Winget_install ¶
Winget_install installs the specified package using winget with standard flags. Example: Winget_install("Visual Studio Code", "Microsoft.VisualStudioCode")
Types ¶
This section is empty.