Skip to content
/ bash-helpers Public template

Template to easily create multi-OS bash helpers for Windows (MSYS2/GitBash/WSL), Ubuntu, and Mac.

Notifications You must be signed in to change notification settings

alanlivio/bash-helpers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bash-helpers

Template to easily create multi-OS bash helpers for Windows (MSYS2/GitBash/WSL), Ubuntu, and Mac. It is useful to let you organize helpers in OS-dependent or program-dependent. The diagram below illustrates how the init.sh loads OS-dependent from os_*.bash (files after testing $OSTYPE) and loads program-dependent from programs/<program>.bash (after testing type <program>). At Windows, it also loads ps1 functions from os_win.ps1 as an alias. The project logo refers to the synthetic chemical element Bohrium, which also has BH's initials.

%%{init: {'theme':'dark'}}%%
flowchart LR
    bashrc["~/.bashrc"]
    init["bash-hepers/init.sh"]
    anyos["os_any.bash"]
    oswinps1["os_win.ps1"]
    program-dependent["
        programs/[program].bash
        ...
    "]
    win["os_win.bash"]
    ubu["os_ub.bash"]
    mac["os_mac.bash"]
    bashrc --> |"load"| init
    init --> |"load"| anyos
    anyos --> |"load if type program"| program-dependent
    win --> |"bash alias to each function at"| oswinps1
    init --> |"load if $OSTYPE==msys* || -n $WSL_DISTRO_NAME"| win
    init --> |"load if $OSTYPE==linux*"| ubu
    init --> |"load if $OSTYPE==mac*"| mac
Loading

Install

The bash-helpers project has two requirements: a bash shell and git. So, run on a bash shell with git:

  git clone https://github.com/alanlivio/bash-helpers ~/.bh &&\
    echo "source ~/.bh/init.sh" >> ~/.bashrc &&\
    source ~/.bashrc

Alternatively, you can see the skel/.bashrc as an example.

On Win, you run the above program at GitaBash installed with GitForWindows. If you also use WSL, you can share the same BH repo by doing a symbolic link to it with ln -s /mnt/c/<user>/.bh ~/.bh.

OS-dependent

os_any

OS-independent helpers are defined in os_any.bash. See some below.

  • bashrc_reload: reload ~/.bashrc.
  • bh_dotfiles_backup,bh_dotfiles_diff,bh_dotfiles_install: backup, diff and install files/dirs defined in BH_DOTFILES. See a BH_DOTFILES var example at skel/.bashrc.
  • decompress_from_url: fetch and decompress to a given folder.
  • decompress: decompress from multiple formats to a given folder.
  • folder_count_files_recursive: count files in the current and subfolder.
  • folder_count_files: count files in the current folder.
  • folder_sorted_by_size: list dir sorted by item size.
  • ssh_fix_permisisons: fix permissions for files in ~/.ssh folder.
  • user_sudo_no_password: disable password when calling sudo (user must be in sudoers).

os_ubu

Ubuntu helpers are defined in os_ubu.bash. See some below.

  • ubu_update: update os and apt.
  • deb_install_file_from_url: fetch and install a deb package.
  • ubu_install_miniconda: fetch and install miniconda.
  • user_sudo_no_password: remove password for current user sudo.
  • gnome_dark_mode: enable gnome dark mode.
  • gnome_nautilus_list_view: enable nautilus list view.

os_mac

Mac helpers are defined in os_mac.bash. See some below.

  • mac_update: update os and brew.
  • mac_install_brew: install brew package manager

os_win

Win helpers are defined in os_win.bash and os_win.ps1, see some below.

  • win_dir_as_unix_format: convert dir to a unix format using '/'. It uses cygpath -m in GitBash/MSYS2, while uses wslpath -m in WSL.
  • win_disable_edge_ctrl_shift_c: disable Edge shorcut ctrl+shift+c to developer (require sudo).
  • win_disable_explorer_clutter: disable explorer shows recent, frequent, and recommendations and hides extensions.
  • win_disable_osapps_unused: remove unused apps.
  • win_disable_password_policy: disable password policy requirement (require sudo).
  • win_disable_shortcuts_unuseddisable accessibility, rotation, lang hotkeys.
  • win_disable_sounds: disable systems sound (e.g., bells).
  • win_disable_taskbar_clutter: disable taskbar shows task search, view, copilot buttons, and animation.
  • win_disable_web_search_and_widgets: disable Windows Web search and Widgets (require sudo on win11).
  • win_enable_hyperv: enable hyper-v virtualization (require sudo).
  • win_enable_osapps_essentials: install WindowsStore, WindowsCalculator, WindowsPhotos, WindowsFeedbackHub, and WindowsCamera.
  • win_enable_sudo: enable sudo elevation (using sudo config at win11 and gsudo at win10).
  • win_env_add_machine: add variable to system env variables (require sudo).
  • win_env_add: add variable to user env variables.
  • win_env_path_add: add dir to the path at user scope.
  • win_env_path_show: show windows path as list.
  • win_env_show: show env variables.
  • win_explorer_hide_home_dotfiles: set as hidden files starting with "." at home folder
  • win_image_cleanup: win image cleanup (require sudo).
  • win_install_ubuntu: install WSL 2 and Ubuntu.
  • win_policy_reset: reset group policy (require sudo).
  • win_ssh_agent_and_add_id_rsa: set ssh-agent to automatically startup using $HOME/.ssh/id_rsa as Identity (require sudo).
  • win_start: (from wsl): call cmd start from current wsl path.
  • win_update: update winget packages and, if has sudo, install os update.
  • wsl_install_cuda_cudnn: (from wsl): install cuda and cudadnn.

program-dependent

Python

Python helpers are defined in programs/python.bash. See some below.

  • python_check_tensorflow: check Tensorflow GPU support.
  • python_clean_cache: clean cache
  • python_setup_install_local: install from a pkg folder with setup.py.
  • python_setup_upload_pip: upload to pip from a pkg folder with setup.py.
  • python_setup_upload_testpypi: upload to testpypi repository from a pkg folder with setup.py.

Conda

Conda helpers are defined in programs/conda.bash. See some below.

  • conda_env_create_from_enviroment_yml: create env from environment.yml.
  • conda_env_update_from_enviroment_yml: update env from environment.yml.

Docker

Docker helpers are defined in programs/docker.bash. See others below.

  • docker_prune: clean, unused images and containers
  • docker_run_at_same_folder: run, from an image, a program line using the current folder as the working folder

others

See other programs at:

References

This project takes inspiration from: