aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2017-10-01 19:16:40 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2017-10-01 19:18:06 +0300
commite78d34b559a7e2f40bc4897ddf7bef62b381f2aa (patch)
tree4dfe52bc8040f999589f2f4f15eada11e11c1377
parentpath_add: prepend (diff)
downloadlinux-home-e78d34b559a7e2f40bc4897ddf7bef62b381f2aa.tar.gz
linux-home-e78d34b559a7e2f40bc4897ddf7bef62b381f2aa.zip
add python.sh
This is a stupid way to add your user's pip binary directory to $PATH.
Diffstat (limited to '')
-rw-r--r--%HOME%/.bash_utils/python.sh43
-rw-r--r--%HOME%/.bashrc17
2 files changed, 52 insertions, 8 deletions
diff --git a/%HOME%/.bash_utils/python.sh b/%HOME%/.bash_utils/python.sh
new file mode 100644
index 0000000..6f74f8b
--- /dev/null
+++ b/%HOME%/.bash_utils/python.sh
@@ -0,0 +1,43 @@
+#!/usr/bin/env bash
+
+# Copyright (c) 2017 Egor Tensin <Egor.Tensin@gmail.com>
+# This file is part of the "Cygwin configuration files" project.
+# For details, see https://github.com/egor-tensin/cygwin-home.
+# Distributed under the MIT License.
+
+# This is a half-assed way to automatically add your user's pip binary
+# directory to $PATH.
+
+source "$HOME/.bash_utils/path.sh"
+
+python_setup_() (
+ set -o errexit -o nounset -o pipefail
+
+ if [ "$#" -ne 1 ]; then
+ echo "usage: ${FUNCNAME[0]} PYTHON_EXE"
+ return 1
+ fi
+
+ local python="$1"
+
+ local user_base
+ user_base="$( "$python" -m site --user-base )"
+
+ local user_bin="$user_base/bin"
+ [ -d "$user_bin" ] || return 1
+ echo "$user_bin"
+)
+
+python_setup() {
+ local user_bin
+
+ if command -v python3 &> /dev/null; then
+ user_bin="$( python_setup_ python3 )" \
+ && path_export "$user_bin"
+ elif command -v python &> /dev/null; then
+ user_bin="$( python_setup_ python )" \
+ && path_export "$user_bin"
+ fi
+}
+
+python_setup
diff --git a/%HOME%/.bashrc b/%HOME%/.bashrc
index 233c4e9..e153a13 100644
--- a/%HOME%/.bashrc
+++ b/%HOME%/.bashrc
@@ -43,14 +43,15 @@ alias ssh-copy-id='ssh-copy-id -i'
alias cls='echo -en "\ec"'
alias copy='xclip -sel clip'
-[ -r "$HOME/.bash_utils/cxx.sh" ] && source "$HOME/.bash_utils/cxx.sh"
-[ -r "$HOME/.bash_utils/distr.sh" ] && source "$HOME/.bash_utils/distr.sh"
-[ -r "$HOME/.bash_utils/file.sh" ] && source "$HOME/.bash_utils/file.sh"
-[ -r "$HOME/.bash_utils/git.sh" ] && source "$HOME/.bash_utils/git.sh"
-[ -r "$HOME/.bash_utils/os.sh" ] && source "$HOME/.bash_utils/os.sh"
-[ -r "$HOME/.bash_utils/path.sh" ] && source "$HOME/.bash_utils/path.sh"
-[ -r "$HOME/.bash_utils/ruby.sh" ] && source "$HOME/.bash_utils/ruby.sh"
-[ -r "$HOME/.bash_utils/text.sh" ] && source "$HOME/.bash_utils/text.sh"
+[ -r "$HOME/.bash_utils/cxx.sh" ] && source "$HOME/.bash_utils/cxx.sh"
+[ -r "$HOME/.bash_utils/distr.sh" ] && source "$HOME/.bash_utils/distr.sh"
+[ -r "$HOME/.bash_utils/file.sh" ] && source "$HOME/.bash_utils/file.sh"
+[ -r "$HOME/.bash_utils/git.sh" ] && source "$HOME/.bash_utils/git.sh"
+[ -r "$HOME/.bash_utils/os.sh" ] && source "$HOME/.bash_utils/os.sh"
+[ -r "$HOME/.bash_utils/path.sh" ] && source "$HOME/.bash_utils/path.sh"
+[ -r "$HOME/.bash_utils/python.sh" ] && source "$HOME/.bash_utils/python.sh"
+[ -r "$HOME/.bash_utils/ruby.sh" ] && source "$HOME/.bash_utils/ruby.sh"
+[ -r "$HOME/.bash_utils/text.sh" ] && source "$HOME/.bash_utils/text.sh"
export PYTHONSTARTUP="$HOME/.pythonrc"