-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathindex.js
104 lines (99 loc) · 2.03 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
const app = new Vue({
el: '#app',
data() {
return {
copied: false,
owner: {
r: 1,
w: 0,
x: 0,
},
groups: {
r: 0,
w: 0,
x: 0,
},
others: {
r: 0,
w: 0,
x: 0,
},
};
},
filters: {
bit(value) {
return String(~~value);
},
},
computed: {
ownerOctal() {
return String(this.getBinaryAsOctal(this.owner));
},
groupsOctal() {
return String(this.getBinaryAsOctal(this.groups));
},
othersOctal() {
return String(this.getBinaryAsOctal(this.others));
},
ownerPermission() {
return String(this.getBinaryAsPermission(this.owner));
},
groupsPermission() {
return String(this.getBinaryAsPermission(this.groups));
},
othersPermission() {
return String(this.getBinaryAsPermission(this.others));
},
fullOctal() {
return `${this.ownerOctal}${this.groupsOctal}${this.othersOctal}`;
},
},
methods: {
getBinaryAsOctal(object) {
let output = 0;
if (object.x) {
output += 1
}
if (object.w) {
output += 2
}
if (object.r) {
output += 4
}
return output;
},
getBinaryAsPermission(object) {
let output = '';
if (object.r) {
output += 'r'
} else {
output += '-'
}
if (object.w) {
output += 'w'
} else {
output += '-'
}
if (object.x) {
output += 'x'
} else {
output += '-'
}
return output;
},
copyToClipboard() {
this.copied = true;
const command = `sudo chmod ${this.fullOctal}`;
// add to clipboard
const el = document.createElement('textarea');
el.value = command;
el.setAttribute('readonly', '');
el.style.position = 'absolute';
el.style.left = '-9999px';
document.body.appendChild(el);
el.select();
document.execCommand('copy');
document.body.removeChild(el);
},
},
});