Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fish support based on macOS support #100

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions bash-zsh-fish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/bash
# macOS does not come with readlink or realpath, so we need to take a portable substitute
source "./util/realpath.sh"

case $os in
"Linux")
BASHRC=`readlink -f $HOME/.bashrc`
ZSHRC=`readlink -f $HOME/.zshrc`
FISHRC=`readlink -f $HOME/.config/fish/config.fish`
;;
"Darwin")
BASHRC=`realpath $HOME/.bashrc`
ZSHRC=`realpath $HOME/.zshrc`
FISHRC=`realpath $HOME/.config/fish/config.fish`
;;
*) echo "Operating system not supported. Exiting."
exit 1
;;
esac

which bash &> /dev/null
check_bash="$?"

which zsh &> /dev/null
check_zsh="$?"

which fish &> /dev/null
check_fish="$?"

if [ "$#" = 0 ]; then
exit
fi

if [ "$check_bash" = 0 ]; then
bash shellrc.sh "$1" "$BASHRC"
if [ ! "$1" = "list" ]; then
echo "To activate in current terminal window"
echo "run ${bold}source ~/.bashrc${normal}"
fi
fi

if [ "$check_zsh" = 0 ]; then
bash shellrc.sh "$1" "$ZSHRC"
if [ ! "$1" = "list" ]; then
echo "To activate in current terminal window"
echo "run ${bold}source ~/.zshrc${normal}"
fi
fi

if [ "$check_fish" = 0 ]; then
bash shellrc.sh "$1" "$FISHRC"
if [ ! "$1" = "list" ]; then
echo "To activate in current terminal window"
echo "run ${bold}source ~/.config/fish/config.fish${normal}"
fi
fi
30 changes: 0 additions & 30 deletions bash-zsh.sh

This file was deleted.

2 changes: 1 addition & 1 deletion install
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ echo "Press any key to continue, or Ctrl+C to break."
read

mkdir -p $TARGET_DIR
cp * $TARGET_DIR
cp -r * $TARGET_DIR

# add to path
mkdir -p $HOME/.local/bin
Expand Down
86 changes: 86 additions & 0 deletions linux_functions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/bin/bash
#
# If you have found some issues, or some feature request :
# Raise them here : https://github.com/himanshub16/ProxyMan/issues
# Author : Himanshu Shekhar (@himanshub16)
#

# This is the script that provides main script functions for Linux.

function _do_it_for_selection() {
local what_to_do="$1"
for t in "${targets[@]}"
do
case "$t" in
# THIS stmt WILL CAUSE INFINITE RECURSION. DO NOT USE THIS.
# COMMENTED FOR WARNING
# 1) _do_it_for_all "$what_to_do"
# ;;
2) bash "bash-zsh-fish.sh" "$what_to_do"
;;
3) sudo -E bash "environment.sh" "$what_to_do"
;;
4) sudo -E bash "apt.sh" "$what_to_do"
sudo -E bash "dnf.sh" "$what_to_do"
;;
5) bash "gsettings.sh" "$what_to_do"
bash "kde5.sh" "$what_to_do"
;;
6) bash "npm.sh" "$what_to_do"
;;
7) bash "dropbox.sh" "$what_to_do"
;;
8) bash "git.sh" "$what_to_do"
;;
9) sudo -E bash "docker.sh" "$what_to_do"
;;
*) ;;
esac
done
}

function _do_it_for_all() {
# Argument
# $1 : what to do (set/unset/list)

local what_to_do="$1"
if [[ -z "$targets" || "$targets" = "1" ]]; then
bash "bash-zsh-fish.sh" "$what_to_do"
# avoiding /etc/environment in all because it requires logout after unset
# bashrc / zshrc is sufficient, and sudo -E might suffice
if [[ "$what_to_do" = "list" ]]; then
sudo -E bash "environment.sh" "$what_to_do"
fi
bash "gsettings.sh" "$what_to_do"
bash "kde5.sh" "$what_to_do"
bash "npm.sh" "$what_to_do"
bash "dropbox.sh" "$what_to_do"
bash "git.sh" "$what_to_do"

# isn't required, but still checked to avoid sudo in main all the time
SUDO_CMDS="apt dnf docker"
for cmd in $SUDO_CMDS; do
command -v $cmd > /dev/null && sudo -E bash "${cmd}.sh" "$what_to_do" || :
done
else
_do_it_for_selection "$what_to_do"
fi
}

function prompt_for_proxy_targets() {
echo "${bold}${blue} Select targets to modify ${normal}"

echo "|${bold}${red} 1 ${normal}| All of them ... Don't bother me"
echo "|${bold}${red} 2 ${normal}| Terminal (bash/zsh/fish for current user) "
echo "|${bold}${red} 3 ${normal}| /etc/environment"
echo "|${bold}${red} 4 ${normal}| apt/dnf (Package manager)"
echo "|${bold}${red} 5 ${normal}| Desktop settings (GNOME/Ubuntu/KDE)"
echo "|${bold}${red} 6 ${normal}| npm & yarn"
echo "|${bold}${red} 7 ${normal}| Dropbox"
echo "|${bold}${red} 8 ${normal}| Git"
echo "|${bold}${red} 9 ${normal}| Docker"
echo
echo "Separate multiple choices with space"
echo -n "${bold} ? ${normal}" ; read targets
export targets=(`echo ${targets}`)
}
61 changes: 61 additions & 0 deletions macos_functions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/bash
#
# If you have found some issues, or some feature request :
# Raise them here : https://github.com/himanshub16/ProxyMan/issues
# Author : Benjamin Gericke (@deg0nz)
#

# This is the script that provides main script functions for macOS.

function _do_it_for_selection() {
local what_to_do="$1"
for t in ${targets[@]}
do
case "$t" in
# THIS stmt WILL CAUSE INFINITE RECURSION. DO NOT USE THIS.
# COMMENTED FOR WARNING
# 1) _do_it_for_all "$what_to_do"
# ;;
2) bash "networksetup.sh" "$what_to_do"
;;
3) bash "bash-zsh-fish.sh" "$what_to_do"
;;
4) bash "npm.sh" "$what_to_do"
;;
5) bash "git.sh" "$what_to_do"
;;
*) ;;
esac
done
}

function _do_it_for_all() {
# Argument
# $1 : what to do (set/unset/list)

local what_to_do="$1"
if [[ -z "$targets" || "$targets" = "1" ]]; then

bash "bash-zsh-fish.sh" "$what_to_do"
bash "networksetup.sh" "$what_to_do"
bash "npm.sh" "$what_to_do"
bash "git.sh" "$what_to_do"

else
_do_it_for_selection "$what_to_do"
fi
}

function prompt_for_proxy_targets() {
echo "${bold}${blue} Select targets to modify ${normal}"

echo "|${bold}${red} 1 ${normal}| All of them ... Don't bother me"
echo "|${bold}${red} 2 ${normal}| System-wide settings (networksetup)"
echo "|${bold}${red} 3 ${normal}| Terminal (bash/zsh/fish for current user) "
echo "|${bold}${red} 4 ${normal}| npm & yarn"
echo "|${bold}${red} 5 ${normal}| Git"
echo
echo "Separate multiple choices with space"
echo -n "${bold} ? ${normal}" ; read targets
export targets=(`echo ${targets}`)
}
84 changes: 10 additions & 74 deletions main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,62 +11,16 @@
source "./variables.sh"
source "./configs.sh"


function _do_it_for_all() {
# Argument
# $1 : what to do (set/unset/list)

local what_to_do="$1"
if [[ -z "$targets" || "$targets" = "1" ]]; then
bash "bash-zsh.sh" "$what_to_do"
# avoiding /etc/environment in all because it requires logout after unset
# bashrc / zshrc is sufficient, and sudo -E might suffice
if [[ "$what_to_do" = "list" ]]; then
sudo -E bash "environment.sh" "$what_to_do"
fi
bash "gsettings.sh" "$what_to_do"
bash "kde5.sh" "$what_to_do"
bash "npm.sh" "$what_to_do"
bash "dropbox.sh" "$what_to_do"
bash "git.sh" "$what_to_do"

# isn't required, but still checked to avoid sudo in main all the time
SUDO_CMDS="apt dnf docker"
for cmd in $SUDO_CMDS; do
command -v $cmd > /dev/null && sudo -E bash "${cmd}.sh" "$what_to_do" || :
done
else
for t in "${targets[@]}"
do
case "$t" in
# THIS stmt WILL CAUSE INFINITE RECURSION. DO NOT USE THIS.
# COMMENTED FOR WARNING
# 1) _do_it_for_all "$what_to_do"
# ;;
2) bash "bash-zsh.sh" "$what_to_do"
;;
3) sudo -E bash "environment.sh" "$what_to_do"
;;
4) sudo -E bash "apt.sh" "$what_to_do"
sudo -E bash "dnf.sh" "$what_to_do"
;;
5) bash "gsettings.sh" "$what_to_do"
bash "kde5.sh" "$what_to_do"
;;
6) bash "npm.sh" "$what_to_do"
;;
7) bash "dropbox.sh" "$what_to_do"
;;
8) bash "git.sh" "$what_to_do"
;;
9) sudo -E bash "docker.sh" "$what_to_do"
;;
*) ;;
esac
done

fi
}
# Load main functions for current operating system
case $os in
"Linux") source "./linux_functions.sh"
;;
"Darwin") source "./macos_functions.sh"
;;
*) echo "Operating system not supported. Exiting."
exit 1
;;
esac

function _dump_it_all() {
echo "HTTP > $http_host $http_port"
Expand Down Expand Up @@ -140,24 +94,6 @@ function prompt_for_proxy_values() {
echo
}

function prompt_for_proxy_targets() {
echo "${bold}${blue} Select targets to modify ${normal}"

echo "|${bold}${red} 1 ${normal}| All of them ... Don't bother me"
echo "|${bold}${red} 2 ${normal}| Terminal / bash / zsh (current user) "
echo "|${bold}${red} 3 ${normal}| /etc/environment"
echo "|${bold}${red} 4 ${normal}| apt/dnf (Package manager)"
echo "|${bold}${red} 5 ${normal}| Desktop settings (GNOME/Ubuntu/KDE)"
echo "|${bold}${red} 6 ${normal}| npm & yarn"
echo "|${bold}${red} 7 ${normal}| Dropbox"
echo "|${bold}${red} 8 ${normal}| Git"
echo "|${bold}${red} 9 ${normal}| Docker"
echo
echo "Separate multiple choices with space"
echo -ne "\e[5m ? \e[0m" ; read targets
export targets=(`echo ${targets}`)
}

function main() {
case "$1" in
"configs" ) list_configs
Expand Down
Loading