aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/%HOME%/.bash_utils
diff options
context:
space:
mode:
Diffstat (limited to '%HOME%/.bash_utils')
-rw-r--r--%HOME%/.bash_utils/os.sh65
-rw-r--r--%HOME%/.bash_utils/ruby.sh15
2 files changed, 80 insertions, 0 deletions
diff --git a/%HOME%/.bash_utils/os.sh b/%HOME%/.bash_utils/os.sh
new file mode 100644
index 0000000..faada73
--- /dev/null
+++ b/%HOME%/.bash_utils/os.sh
@@ -0,0 +1,65 @@
+#!/usr/bin/env bash
+
+_os=''
+
+detect_os() {
+ command -v uname > /dev/null \
+ && [ "$( uname -o )" == 'Cygwin' ] \
+ && _os='Cygwin' \
+ && return 0
+
+ [ -r /etc/os-release ] \
+ && _os="$( . /etc/os-release && echo "$NAME" )" \
+ && return 0
+
+ return 1
+}
+
+detect_os
+
+os_detected() {
+ test -n "$_os"
+}
+
+is_cygwin() {
+ test "$_os" == 'Cygwin'
+}
+
+is_ubuntu() {
+ test "$_os" == 'Ubuntu'
+}
+
+list_manually_installed_packages_ubuntu() (
+ set -o errexit -o nounset -o pipefail
+
+ comm -23 <( apt-mark showmanual | sort | uniq ) \
+ <( gzip --decompress --stdout -- /var/log/installer/initial-status.gz | sed --quiet 's/^Package: //p' | sort | uniq )
+)
+
+list_packages_cygwin() (
+ set -o errexit -o nounset -o pipefail
+
+ cygcheck --check-setup --dump-only \
+ | tail -n +3 \
+ | cut -d ' ' -f 1
+)
+
+list_packages_ubuntu() (
+ set -o errexit -o nounset -o pipefail
+
+ dpkg --get-selections \
+ | grep --invert-match -- 'deinstall$' \
+ | cut -f 1 \
+ | cut -d ':' -f 1
+)
+
+list_packages() (
+ set -o errexit -o nounset -o pipefail
+
+ if is_cygwin; then
+ list_packages_cygwin
+ elif is_ubuntu; then
+ list_packages_ubuntu
+ fi
+ return 1
+)
diff --git a/%HOME%/.bash_utils/ruby.sh b/%HOME%/.bash_utils/ruby.sh
new file mode 100644
index 0000000..86c2c27
--- /dev/null
+++ b/%HOME%/.bash_utils/ruby.sh
@@ -0,0 +1,15 @@
+#!/usr/bin/env bash
+
+update_ruby_settings() {
+ local user_dir
+ local bin_dir
+
+ command -v ruby &> /dev/null \
+ && command -v gem &> /dev/null \
+ && user_dir="$( ruby -e 'puts Gem.user_dir' )" \
+ && export GEM_HOME="$user_dir" \
+ && bin_dir="$( ruby -e 'puts Gem.bindir' )" \
+ && add_path "$bin_dir"
+}
+
+update_ruby_settings