Skip to content

Commit

Permalink
Installation path updated & execution time improved & redundant funct…
Browse files Browse the repository at this point in the history
…ions removed
  • Loading branch information
mehmetumit committed Jul 28, 2022
1 parent bd5852e commit f9e915f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 54 deletions.
18 changes: 11 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
DEST_DIR ?= /usr/bin
PREFIX ?= /usr/local/
DEST_DIR ?= $(PREFIX)/bin
TARGET_FILE ?= colpick
SRC_FILE ?= colpick

all:
@echo Run \'make install\' to install colpick
@echo Run \'make install\' to install $(SRC_FILE)
@echo Run \'make uninstall\' to uninstall $(SRC_FILE)

install:
@cp colpick $(DEST_DIR)/colpick
@chmod 755 $(DEST_DIR)/colpick
@echo colpick has been installed
@cp $(SRC_FILE) $(DEST_DIR)/$(TARGET_FILE)
@chmod 755 $(DEST_DIR)/$(TARGET_FILE)
@echo $(SRC_FILE) has been installed

uninstall:
@rm -rf $(DEST_DIR)/colpick
@echo colpick has been uninstalled
@rm -f $(DEST_DIR)/$(TARGET_FILE)
@echo $(SRC_FILE) has been uninstalled

62 changes: 22 additions & 40 deletions colpick
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/bin/sh
# _ _ _
# _ _ _
# ___ ___ | |_ __ (_) ___| | __
# / __/ _ \| | '_ \| |/ __| |/ /
#| (_| (_) | | |_) | | (__| <
#| (_| (_) | | |_) | | (__| <
# \___\___/|_| .__/|_|\___|_|\_\
# |_|
#
# |_|
#
#author: Mehmet Ümit Özden
#dependencies: ImageMagick, scrot, xdotool, xclip(optional), notification daemon(optional)
#dependencies: ImageMagick, scrot, xdotool, xclip(optional), notification-daemon(optional)

VERSION="1.0"
TEMP_DIR="/tmp"
Expand Down Expand Up @@ -42,59 +42,41 @@ options:
EOF
}
check_dependencies() {
if [ $COPY_TO_CLIPBOARD == true ]; then
! command -v xclip &>/dev/null &&
echo "xclip need to be installed" && exit 1
if [ $COPY_TO_CLIPBOARD = true ]; then
! command -v xclip >/dev/null && echo "xclip need to be installed" && exit 1
else
! command -v convert &>/dev/null &&
echo "ImageMagick need to be installed" && exit 1
! command -v scrot &>/dev/null &&
echo "scrot need to be installed" && exit 1
! command -v xdotool &>/dev/null &&
echo "xdotool need to be installed" && exit 1
! command -v convert >/dev/null && echo "ImageMagick need to be installed" && exit 1
! command -v scrot >/dev/null && echo "scrot need to be installed" && exit 1
! command -v xdotool >/dev/null && echo "xdotool need to be installed" && exit 1
fi
}
# Converts hex code to rgb which includes hashtag
hex_to_rgb() {
rgb=$(printf "(%d,%d,%d)" 0x"${1:1:2}" 0x"${1:3:2}" 0x"${1:5:2}")
echo $rgb
}
# Get color code depends on color type
get_color_code(){
if [ $COLOR_TYPE == "rgb" ]; then
color_code="$(hex_to_rgb $1)"
else
color_code=$1
fi
echo $color_code
}
main() {
# x,y
mouse_pos=$(xdotool getmouselocation | awk -F"[:a-z=&\"]*" '{printf "%d,%d",$2,$3}')
# Bitmap for high accuarcy and speed
hex_color=$(scrot -o "$TEMP_DIR/colpick.bmp" && convert "$TEMP_DIR/colpick.bmp" -set colorspace RGB -format "#%[hex:p{$mouse_pos}]" info:-)
color_code="$(get_color_code $hex_color)"
# Bitmap for high accuracy and speed
# We can use only ImageMagick too but scrot is much faster
color_code=$(scrot -a $mouse_pos,1,1 -o "$TEMP_DIR/colpick.bmp" && convert "$TEMP_DIR/colpick.bmp" -set colorspace RGB txt:- | ([ $COLOR_TYPE = "rgb" ] && awk 'NR==2{ print $2 }' || awk 'NR==2{ print $3 }') )

if [ $COPY_TO_CLIPBOARD == true ]; then
printf $color_code | xclip -selection clipboard
if [ $COPY_TO_CLIPBOARD = true ]; then
printf "$color_code" | xclip -selection clipboard
fi

if [ $NOTIFY == true ]; then
if [ $NOTIFY = true ]; then
[ $COLOR_TYPE = "rgb" ] && xc="rgb$color_code" || xc="$color_code"
# Solid color icon for notification
convert -bordercolor $BORDER_COLOR -border $BORDER_SIZE -size $ICON_SIZE xc:$hex_color $ICON_PATH
convert -bordercolor $BORDER_COLOR -border $BORDER_SIZE -size $ICON_SIZE xc:"$xc" $ICON_PATH
# Notify the notification manager
notify-send -t $EXPIRE_TIME -i $ICON_PATH $color_code "${NOTIFICATION_MESSAGE}"

notify-send -t $EXPIRE_TIME -i $ICON_PATH "$color_code" "$NOTIFICATION_MESSAGE"
fi

if [ $STDOUT == true ]; then
echo $color_code
if [ $STDOUT = true ]; then
echo "$color_code"
fi
}

check_dependencies

while [[ "$1" ]]; do
while [ "$1" ]; do
case "$1" in
-h|--help) help && exit ;;
-v|--version) echo $VERSION && exit ;;
Expand Down
14 changes: 7 additions & 7 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@

A Linux tool that allows users to pick color on mouse position.
* Integrated configuration option for allowing users to adapt their workflow.
* Bitmap screenshot and mouse position used to get pixel color codes.
* Notifier, hex to RGB conversion and clipboard features implemented.
* 1x1 Bitmap screenshot of mouse position used to get pixel color codes.
* Notifier, color codes(RGB and hex) and clipboard features implemented.

![demonstration](https://raw.githubusercontent.com/mehmetumit/colpick/main/demo/demo.gif)
## Dependencies
* `ImageMagick`
* `scrot`
* `xdotool`
* `xclip` (optional)
* notification daemon (optional)
* notification-daemon (optional)

## Execution Time
```
$ time colpick -n
real 0m0.326s
user 0m0.253s
sys 0m0.135s
real 0m0.057s
user 0m0.037s
sys 0m0.028s
```

## Installation
Expand All @@ -36,7 +36,7 @@ $ git clone https://github.com/mehmetumit/colpick.git
# Change directory
$ cd colpick
# Install with make
$ sudo make install
$ make install
```

## Usage
Expand Down

0 comments on commit f9e915f

Please sign in to comment.