Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
artginzburg committed Aug 19, 2019
0 parents commit c208548
Show file tree
Hide file tree
Showing 7 changed files with 266 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

© 2019 Arthur Factor (fqtr.ga)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
28 changes: 28 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
PREFIX ?= /usr/local
PWD ?= $(shell pwd)
CMD = barhide

.PHONY: install all uninstall update upgrade remove

install:
install $(CMD).sh ${PREFIX}/bin/$(CMD)

all:
@echo "\nUsage: make [option]" \
"\n \033[90m# Option left empty performs install\033[39m" \
"\n uninstall \033[90m# Removes the script\033[39m" \
"\n update \033[90m# Updates only the repo\033[39m" \
"\n upgrade \033[90m# Makes update & install\033[39m" \
"\n remove \033[90m# Moves to trash or deletes\n"

uninstall:
rm -f $(PREFIX)/bin/$(CMD) $(PREFIX)/bin/$(CMD).old

update:
git clone --no-checkout https://github.com/DaFuqtor/$(CMD) ~/$(CMD)/$(CMD).tmp && rm -rf ~/$(CMD)/.git && mv ~/$(CMD)/$(CMD).tmp/.git ~/$(CMD)/ && rmdir ~/$(CMD)/$(CMD).tmp && cd ~/$(CMD) && git reset --hard HEAD

upgrade:
make update && make

remove:
mv $(PWD) ~/.Trash/$(CMD) || rm -rf $(PWD)
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<div align="center">
<h1>barhide</h1>
<p><b>CLI to hide unwanted icons from your menu bar</b></p>
</div>

## Usage

```powershell
barhide [-hV] [options] <app>|<bundle_id>
[-u, --update] # Check for update and ask to install
# Options:
[-f, --force] # Force preference change
```

- barhide SystemUIServer to hide the notification centre icon

## Install · [![GitHub release](https://img.shields.io/github/release/dafuqtor/barhide?label=%20&color=gray)](//github.com/DaFuqtor/barhide/releases)

### Using :beer: [Homebrew](//brew.sh)

```powershell
brew install dafuqtor/tap/barhide
```

### Using `curl`

```powershell
curl -sL raw.githubusercontent.com/DaFuqtor/barhide/master/install.sh | sh
```

### Using Source Code

```powershell
git clone https://github.com/DaFuqtor/barhide
cd barhide
make
```

> Also allows to `make [ upgrade, uninstall ]`
174 changes: 174 additions & 0 deletions barhide.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
#!/usr/bin/env sh

VERSION=0.1.0
CMD='barhide'

name=
app=
id=
rdAble=
invis=
force=

usage() {
cat <<EOF
Usage: $CMD [-hV] [options] <app>|<bundle_id>
$CMD SystemUIServer to hide the notification centre icon
Options:
-f, --force Force preference change
-V, --version Output version
-u, --update Check for update and ask to install
-h, --help This message.
EOF
}

barhide() {
if ! [ "$1" ]; then
usage
return 0
fi
for opt in "${@}"; do
case "$opt" in
-h|--help)
usage
return 0
;;
-V|--version)
echo "$VERSION"
return 0
;;
-u|--update)
echo "$CMD $VERSION"
printf " Checking for the update...\r"
gitver=$(curl -s https://api.github.com/repos/DaFuqtor/$CMD/releases/latest | grep tag_name | head -1 | awk -F: '{ print $2 }' | sed 's/[\",]//g' | tr -d '[:space:]')
if [ "$gitver" = "$VERSION" ]; then
echo " Already up to date. "
else
if [ "$gitver" ]; then
echo " Latest version is $gitver "
read -r -p "Do you want to update? [Enter/Ctrl+C]" response
if [[ $response =~ ^( ) ]] || [[ -z $response ]]; then
if command -v brew > /dev/null && brew list "$CMD" &> /dev/null; then
brew upgrade "$CMD"
else
echo "\n - Downloading latest $CMD ($gitver)"
curl -sL raw.githubusercontent.com/DaFuqtor/"$CMD"/master/install.sh | sh && echo " - Update completed!\n"
fi
else
echo " Enjoy the outdated $CMD"
fi
else
echo " Couldn't check for update!"
wifi_interface=$(networksetup -listallhardwareports | grep -A 1 Wi-Fi | grep Device | awk '{print $2}')
if [ "$(networksetup -getairportpower "$wifi_interface" | awk '{print $4}')" = "Off" ]; then
read -r -p "Wi-Fi Adapter is disabled. Maybe you should consider turning it on? [Enter/Ctrl+C]" response
if [[ $response =~ ^( ) ]] || [[ -z $response ]]; then
networksetup -setairportpower "$wifi_interface" On && sleep 1 && $CMD "${@}"
fi
fi
exit 1
fi
fi
return 0
;;
-f|--force)
force=1
;;
*)
if [ "$name" ]; then
name="$name $opt"
else
name="$opt"
fi
esac
done

if [ $(mdfind kMDItemCFBundleIdentifier = "$name") ]; then
# given bundle id instead of app, get its path
app=$(mdfind kMDItemCFBundleIdentifier = "$name")
id=$name
fi

if ! [ "$app" ]; then
# search for the app
app=$(mdfind -onlyin /Applications/ -onlyin /System/Library/CoreServices/ "(kMDItemContentTypeTree=com.apple.application) && (kMDItemDisplayName == '$name*'cdw)" | head -1)
fi

rdAble=$(basename -s .app "$app")

if [ "$rdAble" ]; then

if ! [ "$id" ]; then
# fast (0.01s-0.02s)
id=$(/usr/libexec/PlistBuddy -c 'Print CFBundleIdentifier' "$app"/Contents/Info.plist)
fi

if ! [ "$id" ]; then
# Search for partial match ~4x slower than PlistBuddy
id=$(mdls -name kMDItemCFBundleIdentifier -raw "$app")
fi

if ! [ "$id" ]; then
# ~8x slower than PlistBuddy
id=$(osascript -e 'id of app "$app"')
fi

if ! [ "$id" ]; then
# Search in running apps, ~2x slower than PlistBuddy
id=$(lsappinfo info -only bundleid "$rdAble" | cut -d '"' -f4)
fi

else
echo "No app with this name"
exit 1
fi

if defaults read "$id" "NSStatusItem Visible Item-0" &> /dev/null; then
if [[ $(defaults read "$id" "NSStatusItem Visible Item-0") = 0 ]]; then
invis=1
fi
else
if ! defaults read "$id" "NSStatusItem Preferred Position Item-0" &> /dev/null; then
echo "Seems like the \"$rdAble\" app has no status item at all"
if [ "$force" ]; then
echo 'Forcing preference change...'
else
echo 'To force showing/hiding this status icon, use -f flag'
exit 1
fi
fi
fi

printf "$rdAble with id $id was found in $app and "

if [ "$invis" ]; then
defaults delete "$id" "NSStatusItem Visible Item-0" && \
echo "shown"
else
defaults write "$id" "NSStatusItem Visible Item-0" 0 && \
echo "hidden"
fi

if pgrep "$rdAble" > /dev/null; then
killall "$rdAble" &> /dev/null
if ! echo "$app" | grep /System/Library/CoreServices/ > /dev/null; then
# App is not from Core, so it's not relaunching itself. Do relaunch
if ! pgrep "$rdAble" > /dev/null; then
# LSOpenURLsWithRole() failed for the application /System/Library/CoreServices/Spotlight.app with error -600.
# rare error appears on opening.
open -a "$rdAble"
fi
fi
fi

}

if [[ ${BASH_SOURCE[0]} != $0 ]]; then
export -f $CMD
else
$CMD "${@}"
exit $?
fi
1 change: 1 addition & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl -# https://raw.githubusercontent.com/DaFuqtor/barhide/master/barhide.sh -o /usr/local/bin/barhide && chmod +x /usr/local/bin/barhide

0 comments on commit c208548

Please sign in to comment.